Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在init上不声明密钥数据的情况下使用vue js_Javascript_Jquery_Vuejs2 - Fatal编程技术网

Javascript 如何在init上不声明密钥数据的情况下使用vue js

Javascript 如何在init上不声明密钥数据的情况下使用vue js,javascript,jquery,vuejs2,Javascript,Jquery,Vuejs2,我使用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_p

我使用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);
    });
谢谢。

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

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


你的代码是什么?请确保你的问题包含a。具有
名字属性的对象是什么?你的代码是什么?请确保你的问题包含a。具有
名字属性的对象是什么?你可以帮我举个完整的例子,我不明白。我添加el:“#dashboard”,数据:{profile:Object,newTodoText:'',visitCount:0,hideCompletedTodos:false,todos:[],error:null}仍然错误:(您可以帮助我完整示例,我不明白。我添加el:“#dashboard”,数据:{profile:Object,newTodoText:'',visitCount:0,hideCompletedTodos:false,todos:[],错误:null}仍然错误:(
data: {
  newTodoText: '',
  visitCount: 0,
  hideCompletedTodos: false,
  todos: [],
  error: null
}