vue后臺管理添加多語言功能的實(shí)現(xiàn)示例
在這家公司一個項目, 需要添加英文版本,就是中英文化了,直接上代碼
1.首先是main.js頁面做配置import VueI18n from ’vue-i18n’Vue.use(VueI18n) // 通過插件的形式掛載const i18n = new VueI18n({ //locale: ’zh-CN’, // 語言標(biāo)識 locale: ’Chinese’, // 語言標(biāo)識 //this.$i18n.locale // 通過切換locale的值來實(shí)現(xiàn)語言切換 messages: { ’Chinese’: require(’./common/lang/zh’), // 中文語言包 ’English’: require(’./common/lang/en’) // 英文語言包 }, //隱藏警告 silentTranslationWarn: true})new Vue({ el: ’#app’, router, i18n, components: { App }, template: ’<App/>’})2.配置相應(yīng)路徑下的語言包,在這兒只顯示部分代碼,需要什么在這兒添加什么即可
en.jsexport const m = { deviceCode: ’Device Code’,//設(shè)備編碼 deviceName: ’Device Name’,//設(shè)備名稱 deviceType: ’Device Type’,//設(shè)備類型 denial: ’Denial’,//拒止 camera: ’Camera’,//攝像機(jī) } zh.jsexport const m = { deviceCode: ’設(shè)備編碼’,//設(shè)備編碼 deviceName: ’設(shè)備名稱’,//設(shè)備名稱 deviceType: ’設(shè)備類型’,//設(shè)備類型 denial: ’拒止’,//拒止 camera: ’攝像機(jī)’,//攝像機(jī)}3.頁面中使用,不同的地方使用,寫法略有不同
(1)placeholder和按鈕的寫法<el-row :gutter='30'> <el-col :span='4'><div class='grid-content bg-purple'> <el-input v-model='value0' :placeholder='$t(’m.placeOne’)'></el-input> </div> </el-col> <el-col :span='8'> <div class='grid-content bg-purple'> <el-button @click='searchData()' type='primary' icon='el-icon-search'>{{ $t(’m.query’) }}</el-button> <el-button @click='dialogVisible = true' type='warning'>{{ $t(’m.AddDevice’) }}</el-button> </div> </el-col></el-row>(2)table的寫法<el-table :data='tableData' stripe style='width: 100%;'> <el-table-column prop='areaName' :label='$t(’m.areaName’)' width='100'> </el-table-column></el-table>(3)子組件彈框?qū)懛?lt;el-dialog :title='$t(’m.Ediedevice’)' :visible.sync='dialogVisibles' width='30%' :before-close='handleClose' :close-on-click-modal=false> <edit-equipment @subsuccess='subsuccess' :editDate='editDate' style='overflow: hidden;'></edit-equipment> </el-dialog>(4)js中拼接字符串寫法strHtml = strHtml + '<td>'+this.$i18n.t(’m.deviceCode’)+':</td>';
以上就是vue后臺管理添加多語言功能的實(shí)現(xiàn)示例的詳細(xì)內(nèi)容,更多關(guān)于vue后臺管理添加多語言功能的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. jsp文件下載功能實(shí)現(xiàn)代碼2. phpstudy apache開啟ssi使用詳解3. jsp實(shí)現(xiàn)登錄驗證的過濾器4. Xml簡介_動力節(jié)點(diǎn)Java學(xué)院整理5. 詳解瀏覽器的緩存機(jī)制6. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程7. 如何在jsp界面中插入圖片8. JSP之表單提交get和post的區(qū)別詳解及實(shí)例9. ASP動態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗分享10. .Net Core和RabbitMQ限制循環(huán)消費(fèi)的方法
