- 安装
npm i vue-i18n -S
建立lang.js
- VueI18n from 'vue-i18n'
- elementEnLocale from 'element-ui/lib/locale/lang/en' // element-ui lang
- elementZhLocale from 'element-ui/lib/locale/lang/zh-CN'// element-ui lang
- enLocale from './en'
- zhLocale from './zh'
- Store from '@/store'
Vue.use(VueI18n) - messages = {
en: {
...enLocale,
...elementEnLocale
},
zh: {
...zhLocale,
...elementZhLocale
}
} - i18n = new VueI18n({
locale: Store.state.language || 'zh', // set locale
messages // set locale messages
}) - default i18n
en.js
- default{
myorder: 'My Order',
}
zh.js default{
myorder: '我的订单',
}
-
main.js加入lang
import i18n from './lang' Vue.use(ElementUI, { size: 'medium', // set element-ui default size i18n: (key, value) => i18n.t(key, value) }) new Vue({ el: '#app', router, store, i18n, components: { App }, template: '<App/>', data: { isMobile: false } })