目標
實時輸入,實時更新,鞏固 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}
},