1,创建英文文件
module.exports = {
lang: 'English',
common:{ //自定义变量名
back: 'back', 变量名必须与中文文件中一致
title: 'title'
}
}
创建中文文件
module.exports = {
lang: '中文',
common:{ //自定义变量名
back: '后退',
title: '标题'
}
}
2,main.js中引入注册
import VueI18n from 'vue-i18n'
// 引入语言包
import LangENUS from './lang/en-us'
import LangZHCN from './lang/zh-cn'
//使用VueI18n
Vue.use(VueI18n)
// 注册i18n实例并引入语言文件
const i18n = new VueI18n({
locale: Vue.ls.get("language", "zh-CN"),
messages: {
'zh-CN': LangZHCN,
'en-US': LangENUS
}
})
new Vue({
router,
store,
i18n, // vue中注册
render: h => h(App)
}).$mount('#app')