VueI18n的应用
生活随笔
收集整理的這篇文章主要介紹了
VueI18n的应用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.npm install vue-i18n
2.在 main.js 中引入 vue-i18n import VueI18n from 'vue-i18n'Vue.use(VueI18n)
3.在main.js中準備翻譯const messages = {zh: {message: {name:'李四'}},en: {message: {name:'lisi'}}
}4.創建帶有選項的 VueI18n 實例const i18n = new VueI18n({locale: localStorage.getItem("language"), // 語言標識
messages
})5.把 i18n 掛載到 vue 根實例上
Vue.config.productionTip = false
new Vue({el: '#app',router,i18n,template: '<App/>',components: {App}6.在 HTML 模板中使用
<div id="app"><h1 style="font-size: 16px; text-align: center;">{{ $t("message.hello") }}</h1></div>
})7.切換語言; this.$i18n.locale = "en";
?
轉載于:https://www.cnblogs.com/huanhuan55/p/9920601.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的VueI18n的应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信视频号如何屏蔽好友点赞? 微信视频号
- 下一篇: vuejs目录结构启动项目安装nodej