npm install vue-i18n@6
import Vue from 'vue';
import VueI18n from 'vue-i18n';
Vue.use(VueI18n);
import zh from './zh';
import en from './en';
const i18n = new VueI18n({
locale: 'zh',
messages: {
zh,
en,
}
})
export default i18n;
import i18n from './util/vueIN'
new Vue({
router,
store,
i18n,
render: h => h(App)
}).$mount('#app')
const zh = {
admin: '后台管理系统',
test: '你好',
language: {
zh: '中文',
en: 'English',
},
}
export default zh;
const en = {
admin: 'admin',
test: 'hello',
language: {
zh: '中文',
en: 'English',
},
}
export default en;
<div>{{$t("admin")}}</div>
<input :placeholder="$t('test')">
<button @click="btn('zh')">中</button>
<button @click="btn('en')">英</button>
btn(type){
this.$i18n.locale=type
console.log(this.$t("language.zh"))
},