cnpm install vue-i18n@6
//在src目录下新建langs文件夹,langs下面index.js文件代码如下
import Vue from 'vue' import Element from 'element-ui' import VueI18n from 'vue-i18n' import enLocale from 'element-ui/lib/locale/lang/en' import zhLocale from 'element-ui/lib/locale/lang/zh-CN' Vue.use(VueI18n) const messages = { en: { ...enLocale }, zh: { ...zhLocale } } // Create VueI18n instance with options const i18n = new VueI18n({ locale: 'zh', // set locale messages, // set locale messages }) Vue.use(Element, { i18n: (key, value) => i18n.t(key, value) }) export default i18n
//main.js
import i18n from '@/lang/index.js'
new Vue({
render: h => h(App),
store,
i18n
}).$mount('#app')
//页面中使用
methods: { change(val) { if (val == 'zh') { this.$i18n.locale = 'zh' } else { this.$i18n.locale = 'en' } } } 标签:国际化,zh,locale,ele,Vue,ui,i18n,import From: https://www.cnblogs.com/txdtxd/p/17991452