繁体   English   中英

如何在没有在init上声明的关键数据的情况下使用vue js

[英]How to use vue js without declared key data on init

我使用 jquery 与 api rest 进行通信数据。并使用 vue js 将数据渲染到我的模板,但我有错误。

[Vue warn]: Error in render function: "TypeError: Cannot read property 'first_name' of undefined"

这是我的代码:

var dashboard = new Vue({
  el: '#dashboard',
  data:{
    profile: {}
  }
});
axios.get(url_profile, { headers: {"Authorization": "JWT " + token} })
    .then(function(res){
        dashboard.$data.profile = res.data;
    })
    .catch(function(err){
        toastr.err(err);
    });

谢谢。

https://v2.vuejs.org/v2/guide/instance.html#Data-and-Methods

如果您知道以后需要一个属性,但它一开始是空的或不存在,则需要设置一些初始值。 例如:

data: {
  newTodoText: '',
  visitCount: 0,
  hideCompletedTodos: false,
  todos: [],
  error: null
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM