[Vuejs]-Basic HTTP request in VueJS

0👍

Move the idk.js logic into your Page2 component. The issue is that when you include idk.js, the element with ID idk won’t exist.

For example, assuming that Page2 is included by App or something like that…

<!-- Page2.vue -->
<template>
  <div id="idk">
  {{ info }} hmm
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data: () => ({ info: null }),
  created () { // 👈 created runs earlier so will get your data quicker
    axios
      .get('https://api.coindesk.com/v1/bpi/currentprice.json')
      .then(response => {
        this.info = response.data // 👈 note "response.data" here
      })
  }
})
</script>

You can then remove idk.js.

Leave a comment