vue-element 项目开发双语网站

  • 安装npm i vue-i18n -S
  • 建立lang.js

  1. VueI18n from 'vue-i18n'
  2. elementEnLocale from 'element-ui/lib/locale/lang/en' // element-ui lang
  3. elementZhLocale from 'element-ui/lib/locale/lang/zh-CN'// element-ui lang
  4. enLocale from './en'
  5. zhLocale from './zh'
  6. Store from '@/store'
    Vue.use(VueI18n)
  7. messages = {
    en: {
    ...enLocale,
    ...elementEnLocale
    },
    zh: {
    ...zhLocale,
    ...elementZhLocale
    }
    }
  8. i18n = new VueI18n({
    locale: Store.state.language || 'zh', // set locale
    messages // set locale messages
    })
  9. default i18n

    en.js

  10. default{
    myorder: 'My Order',
    }
    zh.js
  11. default{
    myorder: '我的订单',
    }

  • main.js加入lang

    import i18n from './lang' 
    Vue.use(ElementUI, {
      size: 'medium', // set element-ui default size
      i18n: (key, value) => i18n.t(key, value)
    })
    new Vue({
    el: '#app',
    router,
    store,
    i18n,
    components: { App },
    template: '<App/>',
    data: {
      isMobile: false
    }
    })
上一篇:python字符串常用的方法解析


下一篇:Android照相机拍照Camera