目标
实时输入,实时更新,巩固 mutations 传参语法
实现步骤
代码示例
App.vue
<input :value="count" @input="handleInput" type="text">
<script>
export default {
methods: {
handleInput (e) {
// 1. 实时获取输入框的值
const num = +e.target.value
// 2. 提交mutation,调用mutation函数
this.$store.commit('changeCount', num)
}
}
}
</script>
store/index.js
mutations: {
changeCount (state, newCount) {
state.count = newCount
}
},