Home > Web Front-end > JS Tutorial > How to realize the international development of vue-i18n and element-ui in the vue project

How to realize the international development of vue-i18n and element-ui in the vue project

php中世界最好的语言
Release: 2018-06-02 10:27:27
Original
2660 people have browsed it

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 project

Install vue-i18n and element-ui plug-in

cnpm i vue-i18n --save-dev 
cnpm i element-ui --save-dev
Copy after login
In 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/>' 
})
Copy after login
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 i18n
Copy after login
In the folder langs

index.js

import en from './en'; 
import cn from './cn'; 
export default { 
 en: en, 
 cn: cn 
}
Copy after login
en.js

import enLocale from 'element-ui/lib/locale/lang/en' 
const en = { 
 message: { 
 'mes': 'hello', 
 }, 
 ...enLocale 
} 
export default en;
Copy after login
cn.js

import enLocale from 'element-ui/lib/locale/lang/zh-CN' 
const cn = { 
 message: { 
 'mes': '你好', 
 }, 
 ...enLocale 
} 
export default cn;
Copy after login
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 filter in vue

##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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template