下包
npm i vue-i18n -S
main.js
import store from './store'
import VueI18n from 'vue-i18n'
import zh from './assets/lang/zh'
import en from './assets/lang/en'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import locale from 'element-ui/lib/locale'
Vue.use(ElementUI);
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: store.state.lang,
messages: {
zh,
en
}
});
locale.i18n((key, value) => i18n.t(key, value));
new Vue({
el: '#app',
router,
store,
i18n,
render: h => h(App)
}).$mount('#app');
zh.js
import zhLocale from "element-ui/lib/locale/lang/zh-CN";
const zh = {
message:{
hi:'嗨'
},
...zhLocale
}
export default zh;
en.js
import enLocale from 'element-ui/lib/locale/lang/en'
const en = {
message:{
hi:'Hi'
},
...enLocale
}
export default en;