zoukankan      html  css  js  c++  java
  • i18n的使用(1)

    既然有用到 i18n 那么,肯定需要先安装啦!

    1:安装方式

    npm install vue-i18n
    

      

    2:使用方式

    1:在main.js引入

    import VueI18n from 'vue-i18n'
    Vue.use(VueI18n)
     
    2:准备本地的翻译信息
    const messages = {
      zh: {
        message: {
          hello: '好好学习,天天向上!'
        }
      },
      en: {
        message: {
          hello: 'good good study, day day up!'
        }
      }
    }
    3:创建带有选项的 i18n实例
    const i18n = new VueI18n({
      locale: 'zh', // 语言标识
      messages
    })
    4:将i18n挂载在vue上
    new Vue({
      el: '#app',
      router,
      i18n,
      components: { App },
      template: '<App/>'
    })

    5:使用方式

        <div id="app">
          <h1 style="font-size: 16px; text-align: center;">{{ $t("message.hello") }}</h1>
        </div>

    效果

     将第三步(创建带有选项的 i18n实例)中的  ‘ locale ’ ,换成 ” en “ ,

    const i18n = new VueI18n({
      locale: 'en', // 语言标识
      messages
    })

    后的效果图

    全部代码

    //main.js
    
    import Vue from 'vue'
    import App from './App'
    import router from './router'
    import 'iview/dist/styles/iview.css' // 引入iview css样式
    import VueI18n from 'vue-i18n'
    
    Vue.config.productionTip = false
    Vue.use(iView) //使用iview组件
    Vue.use(VueI18n)
    
    const messages = {
      zh: {
        message: {
          hello: '共产主义接班人'
        }
      },
      en: {
        message: {
          hello: 'successors to the communist cause!'
        }
      }
    }
    
    const i18n = new VueI18n({
      locale: 'en', // 语言标识
      messages
    })
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      router,
      i18n,
      components: { App },
      template: '<App/>'
    })


    //vue文件
    
    <template>
      <div>
        <div id="app">
          <h1 style="font-size: 16px; text-align: center;">{{ $t("message.hello") }}</h1>
        </div>
      </div>
    </template>
    <style lang="">
      h1{
        color: skyblue;
      }
    </style>
    <script>
    export default {
      data() {
        return {
        };
      }
    };
    </script>
  • 相关阅读:
    如何在Ubuntu Server 18.04上安装Microsoft的Procmon
    如何在Ubuntu 20.04上安装Wine 5.0
    如何在Kali Linux 2020中启用SSH服务
    如何在Ubuntu 20.04 LTS Focal Fossa上安装Apache Groovy
    如何使用命令在Ubuntu 20.04 Linux上安装Vmware Tools
    在Ubuntu 20.04 LTS Focal Fossa上安装Zabbix Agent
    hdu 2089 不要62
    hdu 2093 成绩排名
    hdu 2104 hide handkerchief
    leetcode147对链表进行插入排序
  • 原文地址:https://www.cnblogs.com/yixiongqiang/p/12217018.html
Copyright © 2011-2022 走看看