vue.js国际化 vue-i18n插件的使用详解
时间:2021-08-19 09:49:16|栏目:vue|点击: 次
安装方法
1.使用CDN直接引用
<script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://unpkg.com/vue-i18n/dist/vue-i18n.js"></script>
2.NPM
$ npm install vue-i18n
3.Yarn
$ yarn add vue-i18n
使用方法
在这里只介绍vue的使用方法
<script>
/* 国际化使用规则 */
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const messages = {
en: {
message: {
hello: 'world hello'
}
},
zh: {
message: {
hello: '世界'
}
}
}
const i18n = new VueI18n({
locale: 'zh',
messages
})
export default {
data () {
return {
hello: this.$t('message.hello')
}
},
i18n
}
</script>
HTML
<div id="#app">
<p>{{ $t("message.hello") }}</p>
</div>
上一篇:Vue.js实现价格计算器功能
栏 目:vue
本文标题:vue.js国际化 vue-i18n插件的使用详解
本文地址:http://www.codeinn.net/misctech/168258.html






