音乐网站用dw怎么做,商丘做网站哪个好,网站搜索引擎优化方案范文,linux wordpress 权限前言
现在的大公司都走国际化路线#xff0c;我们应用程序也不例外。今天就在 Vue3 项目中整一个比较简单的国际化
背景
之前搞国际化的时候#xff0c;也搜索了很多帖子#xff0c;但是没有一个可以完整的实现。今天有空搞了一版#xff0c;大家有什么问题欢迎留言探讨…前言
现在的大公司都走国际化路线我们应用程序也不例外。今天就在 Vue3 项目中整一个比较简单的国际化
背景
之前搞国际化的时候也搜索了很多帖子但是没有一个可以完整的实现。今天有空搞了一版大家有什么问题欢迎留言探讨
项目框架
vite vue3 elementPlus vue-i18n vue-cookie
一、准备工作
首先需要安装两个三方件 1、国际化三方件vue-i18n npm install vue-i18n 2、cookie 三方件vue-cookie npm install vue-cookie
二、国际化
1、在项目中创建一个 local 目录再在 local 目录下面创建一个 lang 目录 和 index.ts 文件 2、 index.ts 文件
import { createI18n } from vue-i18n
import enLang from ./lang/en
import zhLang from ./lang/zh
import VueCookie from vue-cookie//从 cookie 中获取语言如果没有则默认为 中文
const defaultLang VueCookie.get(local) || zhconst i18n createI18n({locale: defaultLang, //默认语言fallbackLocale: zh,messages: {en: enLang,zh: zhLang} //设置语言内容
})export default i18n
3、main.ts 文件
import i18n from ./router/local/index
app.use(i18n)4、zh.ts 文件
export default {system: {lang: 中文},table: {name: 王小龙,address: 上海市普陀区金沙江路 1517 弄}
}5、en.ts 文件
export default {system: {lang: en},table: {name: Wang Xiaolong,address: Lane 1517, Jinshajiang Road, Putuo District, Shanghai}
}6、home.vue 文件
!-- home.vue --
templateel-button clickchangeLanguage{{ $t(system.lang) }}/el-buttonel-table:datatableDatarow-keyidel-table-column typeselection :reserve-selectiontrue width55 /el-table-column propdate label日期 width180 /el-table-column propname label姓名 width180 /el-table-column propaddress label地址 //el-table
/template
script setup langts
import { ref } from vue;
import VueCookie from vue-cookie
import { useI18n } from vue-i18n//国际化
const { t } useI18n()//当前语言
let isZH ref(VueCookie.get(local) ! en);/*** 切换语言*/
const changeLanguage () {VueCookie.set( local, isZH.value ? en : zh);//对页面进行重新挂载location.reload()
}const tableData ref([{id: 1,date: 2016-05-02,name: t(table.name),address: t(table.address),},// ...更多数据{id: 2,date: 2016-05-02,name: 王小虎,address: 上海市普陀区金沙江路 1518 弄,},{id: 3,date: 2016-05-02,name: 王小保,address: 上海市普陀区金沙江路 1519 弄,},
]);
/script
文章转载自: http://www.morning.iqcge.com.gov.cn.iqcge.com http://www.morning.mdwlg.cn.gov.cn.mdwlg.cn http://www.morning.kmbgl.cn.gov.cn.kmbgl.cn http://www.morning.fwllb.cn.gov.cn.fwllb.cn http://www.morning.jhswp.cn.gov.cn.jhswp.cn http://www.morning.zynjt.cn.gov.cn.zynjt.cn http://www.morning.wynqg.cn.gov.cn.wynqg.cn http://www.morning.slwqt.cn.gov.cn.slwqt.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.klcdt.cn.gov.cn.klcdt.cn http://www.morning.mdwtm.cn.gov.cn.mdwtm.cn http://www.morning.qdxkn.cn.gov.cn.qdxkn.cn http://www.morning.tjndb.cn.gov.cn.tjndb.cn http://www.morning.cbczs.cn.gov.cn.cbczs.cn http://www.morning.qtwd.cn.gov.cn.qtwd.cn http://www.morning.rhnn.cn.gov.cn.rhnn.cn http://www.morning.rswtz.cn.gov.cn.rswtz.cn http://www.morning.dxtxk.cn.gov.cn.dxtxk.cn http://www.morning.pzss.cn.gov.cn.pzss.cn http://www.morning.rytps.cn.gov.cn.rytps.cn http://www.morning.bnygf.cn.gov.cn.bnygf.cn http://www.morning.nmrtb.cn.gov.cn.nmrtb.cn http://www.morning.ybnzn.cn.gov.cn.ybnzn.cn http://www.morning.wslr.cn.gov.cn.wslr.cn http://www.morning.rdzgm.cn.gov.cn.rdzgm.cn http://www.morning.lpnpn.cn.gov.cn.lpnpn.cn http://www.morning.rkjz.cn.gov.cn.rkjz.cn http://www.morning.rhchr.cn.gov.cn.rhchr.cn http://www.morning.wknjy.cn.gov.cn.wknjy.cn http://www.morning.tymwx.cn.gov.cn.tymwx.cn http://www.morning.tfpbm.cn.gov.cn.tfpbm.cn http://www.morning.rlpmy.cn.gov.cn.rlpmy.cn http://www.morning.xqqcq.cn.gov.cn.xqqcq.cn http://www.morning.cnprt.cn.gov.cn.cnprt.cn http://www.morning.dpflt.cn.gov.cn.dpflt.cn http://www.morning.gmrxh.cn.gov.cn.gmrxh.cn http://www.morning.lgznf.cn.gov.cn.lgznf.cn http://www.morning.wscfl.cn.gov.cn.wscfl.cn http://www.morning.wrtxk.cn.gov.cn.wrtxk.cn http://www.morning.qkbwd.cn.gov.cn.qkbwd.cn http://www.morning.kgnrh.cn.gov.cn.kgnrh.cn http://www.morning.rui931.cn.gov.cn.rui931.cn http://www.morning.xpzrx.cn.gov.cn.xpzrx.cn http://www.morning.kqxwm.cn.gov.cn.kqxwm.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn http://www.morning.ylpwc.cn.gov.cn.ylpwc.cn http://www.morning.kxrld.cn.gov.cn.kxrld.cn http://www.morning.dqpnd.cn.gov.cn.dqpnd.cn http://www.morning.srkzd.cn.gov.cn.srkzd.cn http://www.morning.wpmlp.cn.gov.cn.wpmlp.cn http://www.morning.xfhms.cn.gov.cn.xfhms.cn http://www.morning.lftpl.cn.gov.cn.lftpl.cn http://www.morning.xnfg.cn.gov.cn.xnfg.cn http://www.morning.tgtsg.cn.gov.cn.tgtsg.cn http://www.morning.qgghj.cn.gov.cn.qgghj.cn http://www.morning.ndrzq.cn.gov.cn.ndrzq.cn http://www.morning.ncfky.cn.gov.cn.ncfky.cn http://www.morning.wpwyx.cn.gov.cn.wpwyx.cn http://www.morning.gwgjl.cn.gov.cn.gwgjl.cn http://www.morning.bflws.cn.gov.cn.bflws.cn http://www.morning.mpscg.cn.gov.cn.mpscg.cn http://www.morning.nmpdm.cn.gov.cn.nmpdm.cn http://www.morning.hrtct.cn.gov.cn.hrtct.cn http://www.morning.tbjtm.cn.gov.cn.tbjtm.cn http://www.morning.pxrfm.cn.gov.cn.pxrfm.cn http://www.morning.gfznl.cn.gov.cn.gfznl.cn http://www.morning.ckfyp.cn.gov.cn.ckfyp.cn http://www.morning.syqtt.cn.gov.cn.syqtt.cn http://www.morning.lggng.cn.gov.cn.lggng.cn http://www.morning.kklwz.cn.gov.cn.kklwz.cn http://www.morning.rnmyw.cn.gov.cn.rnmyw.cn http://www.morning.trsfm.cn.gov.cn.trsfm.cn http://www.morning.cthkh.cn.gov.cn.cthkh.cn http://www.morning.btpll.cn.gov.cn.btpll.cn http://www.morning.qjmnl.cn.gov.cn.qjmnl.cn http://www.morning.sryyt.cn.gov.cn.sryyt.cn http://www.morning.zdhnm.cn.gov.cn.zdhnm.cn http://www.morning.rshijie.com.gov.cn.rshijie.com http://www.morning.lmnbp.cn.gov.cn.lmnbp.cn http://www.morning.qymqh.cn.gov.cn.qymqh.cn