码迷,mamicode.com
首页 > 其他好文 > 详细

vue-i18n

时间:2018-07-30 16:44:39      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:hello   style   初始   oca   enter   i18n   common   lan   16px   

安装

npm install vue-i18n

初始化

import VueI18n from ‘vue-i18n‘

Vue.use(VueI18n)

const messages = {
    zh: {
      message: {
        hello: ‘好好学习,天天向上!‘
      }
    },
    en: {
      message: {
        hello: ‘good good study, day day up!‘
      }
    }
}

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

const app = new Vue({
    router,
    i18n,
    ...App
}).$mount(‘#app‘)

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

异步加载语言

...

const i18n = new VueI18n({
    locale: ‘en‘,  // 语言标识
    messages: {
        ‘zh‘: require(‘./common/lang/zh‘),
        ‘en‘: require(‘./common/lang/en‘)
    }
})

...

vue-i18n

标签:hello   style   初始   oca   enter   i18n   common   lan   16px   

原文地址:https://www.cnblogs.com/qq3279338858/p/9390922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!