I am getting error about using vue-i18n dependance.
How should i get the const i18n from main.js to root.js (store)
I am using
- Vuejs 2.X
- Vue-i18n latest
- Vuex For Vuejs 2.X
In main.js (vue-cli)
Vue.use(VueI18n)
const i18n = new VueI18n({
locale: 'en',
messages: {
en: {
message: en
},
cn: {
message: cn
}
}
})
new Vue({
store,
el: '#app',
i18n,
router,
template: '<App/>',
components: { App }
})
In root.js (store)
export const mutations = {
[types.SET_LANGUAGE] (state, data) {
console.log(i18n.locale) // 'i18n' is not defined
localStorage.setItem('language', data)
},
}
As mentioned in my comment, put it in it's own file, eg
i18n.js
Then, in
main.js
androot.js
...