vueでmutation
を介してstate
を更新したのですが、component
側の値が更新されません。
##コード
store/index.js
js
1import 'es6-promise/auto' 2import Vue from "vue" 3import Vuex from "vuex" 4 5Vue.use(Vuex) 6 7const store = new Vuex.Store({ 8 state: { 9 count: 0 10 }, 11 mutations: { 12 countUp(state) { 13 state.count ++ 14 } 15 } 16}) 17export default store
components/TestCount.vue
vue
1<template> 2 <button @click="$store.commit('countUp')">click</button> 3 {{ count }} 4</template> 5 6<script> 7export default { 8 computed: { 9 count() { 10 return this.$store.state.count 11 } 12 } 13} 14</script> 15
getters
など試したのですが、やはり1回目のストアは取得できるのですが、更新後のstate
を取ってきてくれませんでした。
Vuex
側ではstate
が更新されてるのに、テンプレート側では値が反映されないのはなぜでしょうか。
よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。