【发布时间】:2017-06-11 16:40:45
【问题描述】:
问题:尽管在 Vue DevTools 中我正确地传递了 prop,并且 router-view 组件可以访问它需要的正确格式的数据,但每当我尝试从模板中访问任何数据属性时我得到Uncaught TypeError: Cannot read property 'name' of null。这真的很令人困惑,因为从 DevTools 来看,一切都是有效的对象,并且属性不为空。
App.js
const game = new Vue({
el: '#game',
data: function() {
return {
meta: null,
empire: null,
planets: null
};
},
created: () => {
axios.get('/api/game').then(function (response) {
game.meta = response.data.meta;
game.empire = response.data.empire;
game.planets = response.data.planets;
});
},
router // router is in separate file but nothing special
});
main.blade.php
<router-view :meta="meta" :empire="empire" :planets="planets"></router-view>
我的 Component.vue 文件的脚本部分
export default {
data: function() {
return {
}
},
props: {
meta: {
type: Object
},
empire: {
type: Object
},
planets: {
type: Array
}
}
}
有什么想法吗?提前致谢。
【问题讨论】:
-
imgur.com/a/QbYfB - 我的 Vue 开发工具的图像,其中选择了路由器组件。
标签: laravel vue.js vuejs2 vue-component vue-router