无法从Vue数据获取正确的数据

时间:2020-04-28 01:02:39

标签: vuejs2 axios vue-component

我在组件中有以下代码

  data() {
    return {
      data: []
    };
  },
  mounted() {
    this.$axios.get("https://canteen.sjtu.edu.cn/CARD/Ajax/Place").then(res => {
      this.data = res.data;
    });
    console.log(this.data);
  },

但是我无法获取更新的数据,例如console.log(this.data)没有我想要的数据,但是我可以在模板中获取正确的数据

<template>
  <div>
    <div>{{ data }}</div>
  </div>
</template>

如果我console.log(this)挂载了,我可以获得Vue component,在其中可以看到我想要的数据!

非常感谢您的帮助!

0 个答案:

没有答案
相关问题