vue 国际化二

参考:http://kazupon.github.io/vue-i18n/zh/introduction.html
npm install vue-i18n

在main.ts中

//多语言切换
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n({
    locale: 'zh', // 语言标识
    messages: {
        'zh': require('./assets/lang/zh'),
        'en': require('./assets/lang/en')
    }
})

new Vue({
i18n,
router,
store,
render: h => h(App)
}).$mount('#app')

国际化

建立zh.js和en.js内容如下即可
module.exports = { lang:[ {label:"Chinese",value:"zh"}, {label:"English",value:"en"} ], home: { title: "The more you know, the more you win" }, content: { main: "这里是内容" } }

使用

<p class="big_title">{{$t('home.title')}}</p>

js中使用 this.$t('home.title')}

猜你喜欢

转载自www.cnblogs.com/mary-123/p/12128589.html