Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vuex] Do not mutate vuex store state outside mutation handlers #38

Closed
sqal opened this issue Jul 2, 2016 · 1 comment
Closed

[vuex] Do not mutate vuex store state outside mutation handlers #38

sqal opened this issue Jul 2, 2016 · 1 comment

Comments

@sqal
Copy link

sqal commented Jul 2, 2016

vue & vue-i18n version

vue@1.0.26, vue-i18n@4.0.1, vuex@1.0.0-rc

Here's my code:

import Vue from 'vue';
import VueI18n from 'vue-i18n';
import en from 'locales/en';
import pl from 'locales/pl';

Vue.use(VueI18n);

Vue.locale('en', en);
Vue.locale('pl', pl);

Vue.config.lang = 'en';

export function langWatcher(store) {
  store.on('mutation', (mutation, state) => {
    if (mutation.type === 'CHANGE_LANG') {
      Vue.config.lang = state.lang;
    }
  });
}

store.js

import Vue from 'vue';
import Vuex from 'vuex';
import { langWatcher } from '../i18n_old';

import {
  CHANGE_LANG,
} from './mutation-types';


Vue.use(Vuex);

const initialState = {
  lang: 'en',
  langs: ['en', 'pl'],
};

const mutations = {
  [CHANGE_LANG](state, lang) {
    if (state.langs.indexOf(lang) > -1) {
      state.lang = lang;
    }
  },
};

export default new Vuex.Store({
  strict: process.env.NODE_ENV !== 'production',
  state: initialState,
  mutations,
  plugins: [langWatcher],
});

and whenever i change language in vuex store I am getting an error in the console [vuex] Do not mutate vuex store state outside mutation handlers. Can i somehow get rid of this error?

// EDIT: Ok apparently this error shows because i have enabled strict option in vuex store. You can close this issue now :))

@lianmin
Copy link

lianmin commented Mar 24, 2017

I met the same problem. i've solved it in your way. Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants