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'
