【发布时间】:2019-07-29 22:10:01
【问题描述】:
在阅读了许多来自 Vue、Vuex 和 Vue-Router 的示例和文档后,我做了这个项目:https://jsfiddle.net/junihh/30wda1em/5/
当我尝试从 Post 部分加载一行时,即使一切正常,Vuex 存储中的值也是空的。这里是组件:
const PostContent = Vue.component('postcontent', {
data() {
return {
post: this.$store.state.currentPost
// post: {
// title: 'The title',
// content: 'The content for test.'
// }
}
},
template: getTemplate('#tpl-postcontent')
});
这里是更新 state.currentPost 值并调用“postcontent”组件的组件。
const Posts = Vue.component('posts', {
data() {
return {
url_path: '/posts/content',
rows: this.$store.state.dataAll
}
},
methods: {
openPost: function(e)
{
let rowID = e.currentTarget.getAttribute('data-rowid');
let dataAll = this.$store.state.dataAll;
let currentPost = dataAll.filter(row => (row.id == rowID))[0];
this.$store.state.currentPost = currentPost;
}
},
template: getTemplate('#tpl-posts')
});
这里有什么帮助吗?我被这个问题困住了。
【问题讨论】:
标签: vuejs2 vue-component vuex vue-router