我正在使用Laraval Spark,並且在組件中有一個組件。在子組件中使用父組件數據Vue Js
<parent-component :user="user">
<child-component :user="user" :questions="questions"></child-component>
<parent-component>
在我父組件我有我的數據的方法問題的數據:
props: ['user'],
data(){
return {
questions: {
// these are set in another method in this file
},
}
},
正如你所看到的,我已經加入:問題到我的子組件,希望的是能夠使用因爲我需要循環它們,因此該組件中存在問題。
在爲孩子組件我的js文件我有:
props: ['user', 'questions'],
但是,試圖利用問題,當我不像它包含了所有的信息的用戶默認對象。
如何來正確地完成作爲即時通訊只是猜測目前...
下面是子組件的js文件:
Vue.component('control-question-navigation', {
props: ['user', 'questions'],
data() {
return {
//
}
},
methods: {
},
mounted() {
var $this = this;
console.log($this.questions); // return standard object
console.log($this.user); // returns the user data correctly
}
});
你可以顯示你的「孩子組件」,你如何看待問題? – Saurabh
@saurabh更新了問題以顯示js文件。我可以在我的內聯模板中訪問問題數據,但不能在我的js中訪問。 – Lovelock