vue中使用 vue-i18n 实现国际化 $t


1、安装

npm install vue-i18n

2、import

import VueI18n from 'vue-i18n'

3、挂载

Vue.use(VueI18n)

4、创建实例

const vuei18n = new VueI18n({
    locale: 'zh', 
    messages: {
      'zh': require('./static/lang/zh'),
      'en': require('./static/lang/en')
    }
})

5、对应语言包示例

export const zh = {
  name: '小明',
  type: '美丽的女孩'
}
export const en = {
  name: 'Bob',
  type: 'Pretty girl'
}

6、绑定到模板

<span>{{$t('someThing')}}</span> //此处的someThing是变量名

7、在vue方法中切换中英文

this.$vuei18n.locale = 'en'

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM