使用 Vue i18n {{ $t('hello') }}

2019-07-22  本文已影响0人  Mr菜头

vue 完成国际化 使用 vue i18n

1、在 main.js 中 引入 vue-i18n
import vueI18n from ‘vue-i18n’
Vue.use(VueI18n);

const i18n = new VueI18n({
locale: 'zh',
messages:{
'zh':{
hello:'你好'
},
‘en’:{
hello: ‘hello’
}
}

})

new Vue ({
el:‘#app’,
router,
i18n,
store,
template‘<App>’,
components:{ App }
})

<template>
<div class="i18n">
<mt-header fixed title="国际化测试">
<router-link to="/tool" slot="left">
<mt-button icon="back">返回</mt-button>
</router-link>
</mt-header>
<div class="content">
{{ $t('hello') }}
</div>
</div>

</template>

上一篇 下一篇

猜你喜欢

热点阅读