环境:rails webpacker: vue + vuex + vue-router + iview
问题:通过mutation改变state值,通过vue浏览器调试工具可以看到mutation正常触发,但computed获取对应state值的变量却仍然为state的初始值
测试:拉取了项目:https://github.com/gorails-screencasts/vuejs-trello-clone, 在其中测试,表现正常
+++++++++++++++++++
与vuejs-trello-clone项目一样,开启了turbolink, 但没什么帮助,问题依旧
+++++++++++++++++++
补充:
// store.js
state: {
testObj: {},
test: false
},
mutations: {
updateObj (state, obj) {
state.testObj = obj
},
updateTest (state, value) {
state.test = value
}
}
// pageA.vue path:'/pagea' name: 'pagea'
this.$store.commit('updateObj', objData)
this.$store.commit('updateTest', true)
// comB.vue pageA的子组件
computed: {
test() {
return this.$store.state.test
},
testObj() {
return this.$store.state.testObj
}
}
简化的主要过程如上,估计得附一整个项目对找问题原因才有帮助
++++++++++++++++++++++++
2018-04-12补充:
问题重现demo: https://github.com/BoleLee/ra...
启动项目,首页即可测试
此问题已经解决,可见此issue#1423
修改引用 vue 的版本,问题就解决了,可能是由于我有的地方用的是 vue.esm, 有的直接用 vue, 导致冲突,这个问题也引起有时候会报[Vue warn]