1.安装vue-i18n
2.在main.js里面引用
import VueI18n from 'vue-i18n' Vue.use(VueI18n)
3.实例化i18n,并配置默认的语言模式,以及对应的文件(也是在main.js里使用)
如下。cn 中文包对应的是cn.js
en 对应的是英文 en.js 包
const i18n = new VueI18n({ //定义默认语言 locale: 'cn', messages:{ 'cn': require('./common/lang/cn'), 'en': require('./common/lang/en') } })
4.cn.js 怎么写?
module.exports = { placeholder: { phone: '手机号', input_code: '输入验证码', passwordSix: '请输入6到18位密码' }, sidebar: { MyAccount: '账户信息', PersonalInformation: '个人信息', Message: '我的消息', MyWallet: '我的钱包', MyProject: '我的方案' }, home: { SendCode: 'Send verification code success' } }
当然 en.js 也需要配置一份
module.exports = { placeholder: { phone: 'Phone Number', input_code: 'Verification code', passwordSix: 'Please enter 6 to 18 Bit passwords' }, sidebar: { MyAccount: 'My Account', PersonalInformation: 'Personal Information', Message: 'Message', MyWallet: 'My Wallet', MyProject: 'My Project' }, home: { SendCode: 'send Code Success功' } }
5.如何在template中使用?
需要这样渲染出来
{{ $t("sidebar.MyWallet") }} <li>{{ $t("sidebar.MyWallet") }}</li>
当然placeholder也是可以通过他来更改的。
<input type="text" v-model="phoneNumber" :placeholder="$t('placeholder.phone')">
对应好配置好的placeholder就行。
中/English 切换函数
tag () { if (this.$i18n.locale === 'en') { this.$i18n.locale = 'cn' } else { this.$i18n.locale = 'en' } }
在js里如何拿配置过的语言来使用?
this.$t("sidebar.MyAccount")
这里我们使用了mint-ui框架中的Toast消息提示框,想让它根据语言环境来显示不同的提示语。
双语言前
Toast({message: '验证码发送成功'})
更改为双语言后
Toast({message: this.$t("home.SendCode")})
总结
以上所述是小编给大家介绍的vue 国际化 vue-i18n 双语言 语言包,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】
- 林忆莲.2019-0(2023精装版)【环球】【WAV+CUE】
- Supper.Moment.2016-The.Moment【寰亚】【FLAC分轨】
- 范莉丝.1979-送郎一朵牵牛花(LP版)【大联机构】【WAV+CUE】
- 刘宇.2024-宇宙诗人【哔哟哔哟文化】【FLAC分轨】
- 《全景声白噪音》沉浸式大自然助眠 带你听自然的声音[mp3]
- 纯音入心系列纯音乐《古筝精选 十指弹一赏心曲一心奏出世人心》1CD[MP3][582MB]
- 纯音入心系列纯音乐《古筝与现代音乐的交织》1CD[MP3][96MB]
- 王俪婷.2011-ROMANCE【华研国际】【WAV+CUE】
- 狮子合唱团.2016-LION(引进版)【华纳】【WAV+CUE】
- 范文芳.1996-FNNTASY【HYPE】【WAV+CUE】
- 纯音入心系列纯音乐《韵味古筝曲》1CD[MP3][146.2MB]
- 纯音入心系列纯音乐《古筝系列-传统乐曲》1CD[MP3][974.7MB]