问题描述
vuex 通过commit成功改变state数据,在页面中通过computed能获取更新后数据,但视图不更新
1.store部分如下
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
title: '市场'
},
mutations: {
changeTitle (state, obj) {
state.title = obj.title
}
}
})
2.更新state部分代码
created () {
this.$store.commit({
type: 'changeTitle',
title: '购物车'
})
},
computed: {
title: {
get: function () {
return this.$store.state.title
},
set: () => {}
}
}
3.视图部分
<p>{{title}}</p>
疑问:
为什么?视图展示部分一直是市场,而不是更新后的购物车。
created钩子函数涉及到的Vue生命周期的问题