前提・実現したいこと
https://ja.nuxtjs.org/guide/vuex-store/
公式に従って書いているところなのですが、以下のようなエラーが発生しています。
解決策を教えていただければ幸いです。
発生している問題・エラーメッセージ
Cannot read property 'state' of undefined
該当のソースコード
/store/index.js
import Vuex from 'vuex' const store = () => new Vuex.Store({ state: { counter: 0 }, mutations: { increment (state) { state.counter++ } } }) export default store
/components/store.vue
<template> <button @click="$store.commit('increment')">{{ $store.state.counter }}</button> </template>
/pages/test.vue
<template> <section class="container"> <div id="vue"> <store/> </div> </section> </template> <script> import store from '~/components/store.vue' export default { components: { store } }; </script>
状況の再現ができないのですが,①使用しているテンプレートは公式ガイドのもの `$ vue init nuxt-community/starter-template <project-name>` ですか?②`npm run dev`を実行しなおしたりしても状況は変わりませんか?
あなたの回答
tips
プレビュー