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