1. 先创建一个lang 文件夹,创建两个js文件en.js(英文), zh.js(中文), 另外创建一个index.js文件(用于)

           en.jselementUI+国际化 zh.js elementUI+国际化(两者必须保持一致)

 

     2. 在index.js 中引入vue和vue-i18n, 并注册vue-i18n 然后 引入en.js和zh.js两个文件

            (1) elementEnLocale 和elementZhLocale 是element-ui国际化需要的,如果没有使用element-ui,则不需要引入

               (2) locale : 设置的默认的语言

            elementUI+国际化

    3. 将i18n引入main.js, 并在初始化注册       (中间圈住的是element-ui 为了兼容[email protected])

            elementUI+国际化 

 

    4. 使用方式            

        (1)  双括号 {{$t('xxx.yyy')}}

                elementUI+国际化

        (2)  绑定到属性上: :prop="$t('xxx.yyy')"

                elementUI+国际化

         (3) 在js语句中使用`${this.$t('xxx.yyy')}`

    5. 改变语言 将你定义的语言名字赋值给this.$i18n.locale

                elementUI+国际化

    

相关文章:

  • 2022-12-23
  • 2022-02-21
  • 2021-12-25
  • 2021-05-09
  • 2021-09-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
相关资源
相似解决方案