老师为什么会报Computed property "toggle" was assigned to but it has no setter这种错误
来源:4-4 标题栏和菜单栏实现
慕后端3187812
2019-04-18
// book.js
export default {
state: {
fileName: 'Biomedicine|2014_Book_Self-ReportedPopulationHealthA',
toggle: 0
},
mutations: {
'CHANGEFILENAME': (state, fileName) => {
state.fileName = fileName
},
'CHANGETOGGLE': (state, toggle) => {
state.toggle = toggle
}
},
actions: {
changeFileName: ({commit}, fileName) => commit('CHANGEFILENAME', fileName),
changeToggle: ({commit}, toggle) => commit('CHANGETOGGLE', toggle)
}
}
//getters.js
export default {
fileName: state => state.book.fileName,
toggle: state => state.book.toggle
}
//index.js
import Vue from 'vue'
import Vuex from 'vuex'
import book from './modules/book'
import getters from './getters'
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
book
},
getters
})
然后我在computed里面使用…mapGetters([‘toggle’])混入,调用方法使用了this.$store.commit(‘changeToggle’, 0),结果就报错了,但是我百度了下,发现只要不使用混入采用如下写法就没有问题,这是为什么?
toggle: {
get: function () {
return this.$store.state.book.toggle
},
set: function (toggle) {
this.$store.state.book.toggle = toggle
}
},
写回答
2回答
-
慕后端3187812
提问者
2019-04-19
貌似把大写的CHANGETOGGLE和CHANGEFILENAME改成小写驼峰就没事了··
00 -
Sam
2019-04-18
你好,可以提供出错的完整源码吗?
032019-04-19
相似问题