vue项目开发过程中,有的可能需要语言的切换,Element也提供了几种方法,国际化菜单中,我们更多时候想要的是,可以自由的切换,我们基于element改进一下。
我们使用插件vue-i18n 来更好的控制
第一步: 命令行执行 npm install vue-i18n --save
安装好 vue-i18n
保险起见看 package.json里是否安装好
第二步: main.js 引用并全局注册
import Vue from 'vue'
import App from './App'
import router from './router'
import {
store } from './store/index'
import ElementUI from 'element-ui'
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import ElementLocale from 'element-ui/lib/locale'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const messages = {
en: {
...enLocale},
zh: {
...zhLocale}
}
const i18n = new<