[Vuejs]-How to store data from an API with Vue and axios into variable that can be use on another library like chart.js

1👍

this inside your Vue instance points to newCpu instance and this outside of Vue instance points to global window object. Hence,

document.write(this.infoCpu); will try to find the infoCpu inside window object and will not able to find. Hence, resulting undefined.

Example :

const newCpu = new Vue({
  el: '#app',
  data: {
    message: null
  },
  async mounted () {
    this.message = 'Hello vue.js!';
    console.log(this); // Points to vue instance
  }
})

console.log(this); // Points to window object
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <p>{{ message }}</p>
</div>

Leave a comment