Home > Article > Web Front-end > How to realize the international development of vue-i18n and element-ui in the vue project
This time I will bring you how to realize the international development of vue-i18n and element-ui in the vue project, and what are the things to note , the following is a practical case, let’s take a look.
By default you have built a vue project. In the vue projectInstall vue-i18n and element-ui plug-in
cnpm i vue-i18n --save-dev cnpm i element-ui --save-devIn the project file, create as shown below Language pack folder i18n folder Introduce i18n.js in main.js, and introduce element-ui plug-in
import Vue from 'vue' import App from './App' import router from './router' // element-ui import Element from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' Vue.use(Element) // vuei18n import i18n from './i18n/i18n' Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, i18n, components: { App }, template: '<App/>' })In i18n.js
import Vue from 'vue' import locale from 'element-ui/lib/locale' import VueI18n from 'vue-i18n' import messages from './langs' Vue.use(VueI18n) const i18n = new VueI18n({ locale: localStorage.lang || 'cn', messages, }) locale.i18n((key, value) => i18n.t(key, value)) export default i18nIn the folder langsindex.js
import en from './en'; import cn from './cn'; export default { en: en, cn: cn }en.js
import enLocale from 'element-ui/lib/locale/lang/en' const en = { message: { 'mes': 'hello', }, ...enLocale } export default en;cn.js
import enLocale from 'element-ui/lib/locale/lang/zh-CN' const cn = { message: { 'mes': '你好', }, ...enLocale } export default cn;I believe I saw it You have mastered the method in the case of this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading: ##How to use vue to determine the class of dom
The above is the detailed content of How to realize the international development of vue-i18n and element-ui in the vue project. For more information, please follow other related articles on the PHP Chinese website!