国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

vue-i18n實(shí)現(xiàn)中英文切換的方法

瀏覽:37日期:2023-01-09 09:30:09

1.下載

npm install vue-i18n

2.創(chuàng)建中英文包

vue-i18n實(shí)現(xiàn)中英文切換的方法

2.1 中文包

vue-i18n實(shí)現(xiàn)中英文切換的方法

2.2 英文包

vue-i18n實(shí)現(xiàn)中英文切換的方法

3.在main里面引入

import VueI18n from 'vue-i18n';Vue.use(VueI18n);const i18n = new VueI18n({ locale: localStorage.getItem('lang') == (undefined || '' || null) ? 'zh' : localStorage.getItem('lang'), messages: { zh: require('../static/lang/text-zh.json'), en: require('../static/lang/text-en.json') }});new Vue({ router, store, i18n, render: h => h(App)}).$mount('#app');

4.在組件中使用

<div>{{ $t(’footer.home’) }}</div>或者<input type='span' value='' :placeholder='$t(’footer.home’)' v-model='search' />或者this.$toast(this.$t(’footer.home’))

5.使用按鈕進(jìn)行手動(dòng)切換,這里我用了switch用true和false來識(shí)別中英文,用這種方法也可以用于其他語言切換

<switch @change='changeEn' :checked='zhOren' />changeEn(e) { if (e.target.value) {//中文this._i18n.locale = ’zh’;localStorage.setItem(’lang’, ’zh’); } else {//英文this._i18n.locale = ’en’;localStorage.setItem(’lang’, ’en’); }}

以上就是vue-i18n實(shí)現(xiàn)中英文切換的方法的詳細(xì)內(nèi)容,更多關(guān)于vue 中英文切換的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 山阴县| 九龙坡区| 从江县| 长丰县| 南城县| 治县。| 桦川县| 沅江市| 榕江县| 绥化市| 闻喜县| 汾阳市| 武定县| 措勤县| 烟台市| 册亨县| 汤原县| 那坡县| 嵩明县| 灵璧县| 威宁| 云龙县| 沙洋县| 墨脱县| 潢川县| 永清县| 黑山县| 西乌珠穆沁旗| 绥德县| 千阳县| 故城县| 百色市| 漳平市| 北安市| 噶尔县| 卓资县| 仁怀市| 齐齐哈尔市| 德州市| 乃东县| 武义县|