2017-10-11 10 views
-1

私は、テンプレートデータを描画するためにvue jsを使用しますが、エラーがあります。initで宣言されたキーデータなしで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); 
    }); 

感謝。あなたのコードについて

+0

何? – Aer0

+1

質問に[mcve]が含まれていることを確認してください。 – evolutionxbox

+0

'first_name'属性を持つオブジェクトは何ですか? – Maxim

答えて

2

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

If you know you’ll need a property later, but it starts out empty or non-existent, you’ll need to set some initial value. For example:

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

あなたは完全な例で私を助けることができます、私は理解できません。 Iは ELを追加: '#dashboard' \tデータ:{ \t \tプロファイル:オブジェクト、 \t \t newTodoText: ''、 \t \t visitCount:0、 \t \t hideCompletedTodos:偽、 \t \tドス。 []、 \t \tエラー:null \t} まだエラー:( –

+0

ありがとう –

関連する問題