uniapp使用该方式已过时,请使用的官方的使用方式 地址:官方加载方式
- 将语言国际化文件 lang 放入到common 文件下
2.在 main.js 文件中
import App from './App'
import i18n from '@/common/lang/lang.js'
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
//语言国际化挂载
Vue.prototype._i18n = i18n
//切换语言
Vue.prototype.changeLang = function(code) {
var curr_lang = uni.getStorageSync('curr_lang')
if (curr_lang != code) {
curr_lang = this._i18n.locale = code
}
uni.setStorageSync('curr_lang', curr_lang)
}
App.mpType = 'app'
const app = new Vue({
i18n,
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
return { app }
}
// #endif
3.在vue中使用,注意 nvue 使用略有不同,
<view class="item-tile">
{{i18n.title}}
</view>
computed: {
i18n() {
return this.$t('home')
},
common() {
return this.$t('common')
}
},
附加:lang
- vue-i18n.js 下载地址:https://download.csdn.net/download/qq_32852047/85752299