关于uni-app的国际化 ,我是看的这位前辈的分享
国际化多语言
我看评论里 有关nvue使用国家化插件(i18n)存在各项问题;并且搜了下社区有一位前辈已经给了一个方案
nvue国际化
在这里 贴一下自己研究的一个投机取巧的方案,希望能帮到各位:
- 就是依赖官方提供的globalData,做一个过渡就可以了;
export default {
globalData: {
http: '',
_i18n: '',
$t: ''
},
onLaunch: function() {
let context = this;
this.globalData.http = this.$http //这是我适用nvue的网络请求
this.globalData._i18n = this.$i18n //这是原型链上的$i18n
this.globalData.$t = function(str) {
let $i18n = getApp().globalData.$i18n//这里去拿global的i18n
return context.$t(str)
}
}
}
这是在nvue页使用
computed: {
i18n(){
return getApp().globalData.$t('cn')//当然页面中就是按Vue页面里那样使用了
}
}
就这样,我在ios模拟器上测试正常,其他应该也是可以的;