1. Vue3 使用国际化模版生成的程序,如何在纯的js文件或者公共的js文件中使用?
2. Vue3 使用国际话,如何在json中使用,使用的方法和在pages.json的使用方法一致吗?
问题1:
在使用vue2的使用,可以使用下面中
import messages from '@/locale/index.js'
import VueI18n from 'vue-i18n'
import Vue from 'vue'
Vue.use(VueI18n)
const i18n = new VueI18n({locale: uni.getLocale(),messages})
加入单独的js文件中,国际化单独的js或者公共的js,本人没有尝试,因为使用的是
Vue3开发的程序,那么Vue3的模式下如何使用?
本人使用用国际化模版搭建的程序,其中main.js如下
import App from './App'
import messages from './locale/index'
let i18nConfig = {
locale: uni.getLocale(),
messages
}
// #ifndef VUE3
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n(i18nConfig)
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
i18n,
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import {
createSSRApp
} from 'vue'
import {
createI18n
} from 'vue-i18n'
const i18n = createI18n(i18nConfig)
export function createApp() {
const app = createSSRApp(App)
app.use(i18n)
return {
app
}
}
问题2:
在自定的json文件中,可以使用类似于pages.json中的方法实现国际话吗?
[{
"fun_id": 0,
"fun_type": 3,
"fun_name": "%dev.fun_name1%",
"fun_desc": "%dev.fun_desc1%",
"show_seq": 0
},
{
"fun_id": 0,
"fun_type": 3,
"fun_name": "%dev.fun_name2%",
"fun_desc": "%dev.fun_desc2%",
"show_seq": 0
},
]
1 个回复
9***@qq.com - 一个小白
遇到同样的问题了,不知道官方为什么不支持VUE3的开发,多写几个模板
JS文件到底怎么引入vue-i18并使用,按官方的写法只有VUE2能用