原网页网址:https://ask.dcloud.net.cn/article/35102
踩了很多坑,终于捣鼓出来了。
main.js
import Vue from 'vue' import App from './App' import VueI18n from 'vue-i18n' Vue.use(VueI18n) Vue.config.productuinTip = false const i18n = new VueI18n({ locale: 'en-US', messages: { 'en-US': { index: { invite: 'Invite', game: 'Game' } }, 'zh-CN': { index: { invite: '邀请', game: '游戏' } } } }) Vue.prototype._i18n = i18n App.mpType = 'app' const app = new Vue({ i18n, ...App }) app.$mount()
uniapp 不支持在取值表达式中直接调方法,因此,$t方法不可用,所以通过计算属性的方式:
index.vue
<template> <view class="uni-content"> <text>{{ i18n.invite }}</text> <text>{{ i18n.game }}</text> </view> </template> <script> export default { computed: { i18n () { return this.$t('index') } } } </script> <style> </style>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。