【发布时间】:2020-09-17 10:28:39
【问题描述】:
我目前正在尝试学习 Vuex。
我希望每次使用突变(changeNumber).
let state = {
counter: 0,
someOtherValue: 'Text'
}
let changeNumber = {
increment(state) {
state.counter += 1
}
}
let store = new Vuex.Store({
changeNumber,
state
})
Vue.component('counter-button', {
computed: {
counter() {
return this.$store.state.counter
}
},
template: `<input :value="$store.state.counter" @click="$store.commit('increment')" type="button">`
})
Vue.component('some-component', {
computed: {
someOtherValue() {
return this.$store.state.someOtherValue
}
},
template: '<div>{{ someOtherValue }}</div>'
})
new Vue({
el: '#app',
store,
template: '<some-component></some-component>',
})
我的代码被机器人更正了,我收到了两个错误。我的代码有什么问题?
Err) clicking on the paragraph causes the number value to change
Err) triggering the changeNumber mutation causes the number value to change
【问题讨论】:
-
到目前为止你尝试过什么?我认为您应该研究
Vuex.Store()的论点。 -
我已尝试将代码重新格式化为我认为已更正的内容,但这是我所取得的最远距离。能详细点吗?
标签: javascript html vue.js vuex