uni-app i18n

下载 vue-i18n

npm/cnpm i vue-i18n

声明

main.js

import Vue from 'vue'
import App from './App'
import VueI18n from 'vue-i18n';
import en from './common/en.js';
Vue.use(VueI18n)  
Vue.config.productionTip = false

const i18n = new VueI18n({ 
    locale: 'en-cont',
    messages:{
        'en-cont': en,
    }
}) 
Vue.prototype._i18n = i18n
App.mpType = 'app'

const app = new Vue({
    i18n, 
    ...App
})
app.$mount()

使用

<template>
    <view class="product-page">
        {{ i18n.title }}
    </view>
</template>

<script>
    export default {
        data() {
            return {
                msg:'hello'
            }
        },
        methods: {
            
        },
        computed:{
            i18n(){
                return this.$t('product')
            }
        },
    }
</script>

<style>
</style>

数据

en.js

export default {
    lang: 'en',
    title:'111'
}

获取当前设备语言

const res = uni.getSystemInfoSync();
let cl=uni.getStorageSync('currentLan')

竖屏锁定

// #ifdef APP-PLUS
plus.screen.lockOrientation('portrait-primary');
// #endif
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容