お世話になります。vuex初心者ですが、開発してる中でミューテーションエラーが解決できず質問させていただきました。
システム構成は、nuxt + vuex-module-decoratorsになります。
nuxt側からは、Actionを呼んで、ActionからMutationを呼んでるためエラーにならない認識だったのですがエラーになります。
@nuxt/cli v2.15.8
vuex-module-decorators:2.0.0
エラー内容が以下になります。
client.js?06a0:103 Error: [vuex] do not mutate vuex store state outside mutation handlers.
コードは以下になります。
vue
1// test.vue 2async asyncData({params, $axios}) { 3 testModule.setMyFriends(friends) 4}
vue
1import { Mutation, Action, VuexModule, getModule, Module } from "vuex-module-decorators"; 2import store from "@/store/store"; 3import {Friend} from "~/@types/entity/Friend"; 4 5export interface TestState { 6 7} 8@Module({ dynamic: true, store, name: 'Test', namespaced: true }) 9class Test extends VuexModule implements TestState { 10 friends: Friend[] = [] 11 12 @Mutation 13 setFriends(friends: Friend[]) { 14 this.friends = friends 15 } 16 17 @Action 18 public setMyFriends(friends: Friend[]) { 19 this.setFriends(friends) 20 } 21} 22export const barModule = getModule(Test);
あなたの回答
tips
プレビュー