vue-element-admin international application

As the project ui framework uses element, so international but also its internationalization. Complete code. At the same time the current  lang language exists  cookiein order to be able to remember the next time you open the page language set last.

# Global lang

Code Address: @ / lang currently configured with both English and Chinese languages.

At the same time  @/lang/index.js it introduced a  element-uilanguage pack

use:

// $t 是 vue-i18n 提供的全局方法,更多信息请查看其文档
$t('login.title') 

# Asynchronous lang

There are only certain pages need lang, such as  @/views/i18n-demo page

import local from './local'

this.$i18n.mergeLocaleMessage('en', local.en) this.$i18n.mergeLocaleMessage('zh', local.zh) 

#js use $ t

If you use such  selectcomponents, its value is through  v-forfrom, such as:

<el-select v-model="value"> <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/> </el-select> 
this.options = [
  { value: '1', label: this.$t('i18nView.one') }, { value: '2', label: this.$t('i18nView.two') }, { value: '3', label: this.$t('i18nView.three') } ] 

In this case, international only once, because in js in this.optionstime, it will not end with your local data and execute only during initialization  langand change of change, so you need to langchange the time manually reset set this.options.

export default {
  watch: { lang() { this.setOptions() } }, methods: { setOptions() { this.options = [ { value: '1', label: this.$t('i18nView.one') }, { value: '2', label: this.$t('i18nView.two') }, { value: '3', label: this.$t('i18nView.three') } ] } } }

http://www.kemaisii.cn

http://www.eternelle.cn
http://www.yajuxuan.cn
http://www.nodonkg.cn
http://www.yurunyipinn.cn
http://www.niudangjiaa.cn
http://www.feikeshoubiaoo.cn
http://www.yumengse.cn
http://www.parniss.cn
http://www.sensefadd.cn
http://www.youmaqi.cn
http://www.yinghengg.cn
http://www.xizuann.cn
http://www.vapsint.cn
http://www.moshii.cn
http://www.shamandaweiyu.cn
http://www.taiguangyinlou.cn
http://www.dexidunn.cn
http://www.marbooo.cn

Guess you like

Origin www.cnblogs.com/zjhcap/p/11493768.html