vuex使用mapState会报错
export default new Vuex.Store({state: {
ws_:'',
callState:'',
},
mutations: {
changeCallState(state,callState) {
// 变更状态
state.callState = callState;
},
initSocketState(state,data) {
state.ws_ = new WebSocket(data);
}
},
actions: {
},
modules: {
}
})
然后我页面引入是
computed: {
...mapState(['callState','ws_']),},
methods: {
...mapMutations(['changeCallState', // 将 `this.changeCallState()` 映射为 `this.$store.changeCallState('')`
'initSocketState'
]),
}
但是我在页面的
mounted() {
this.initSocketState('456')
},
只要赋值浏览器就会出现这个,,请问是为什么[Vue warn]: Computed property "ws_" was assigned to but it has no setter.
回答
不能直接给 vuex state 里面的参数赋值
建议先去看官方文档
state修改,推荐使用 mutation;多看下文档
以上是 vuex使用mapState会报错 的全部内容, 来源链接: utcz.com/a/39369.html