语言国际化----vue-i18n
// uniapp
- 安装依赖包
npm i vue-i18n –S - 在根目录创建一个 lang的文件夹,并且在lang文件夹内创建cn.js 和 en.js
- 打开 main.js, 注入Vue实例中
- 配置语言包, 并且暴露出去:
cn.js
en.js
- 页面渲染:

- 切换语言:
- tabBar 语言切换用
import Vue from 'vue'
import App from './App'
import VueI18n from 'vue-i18n' // 语言国际化
Vue.use(VueI18n)
Vue.prototype._i18n = i18n
App.mpType = 'app'
const i18n = new VueI18n({
locale:'cn',//默认中文,也可根据系统语言动态设置
messages:{
'cn':require('./lang/cn.js'),//中文包
'en':require('./lang/en.js'),// 英文包
}
})
const app = new Vue({
...App,
i18n
})
app.$mount()tooglang(){
if(this.$i18n.locale == 'cn'){
this.$i18n.locale = 'en'
}else{
this.$i18n.locale = 'cn'
}
}uni.setTabBarItem({
index: 1,
text: that.$t('tabBar.index1')
});
浙公网安备 33010602011771号