congming_huose-apk/main.js

73 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2025-11-08 11:30:06 +08:00
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
// 引入 HTTP 拦截器
import httpInterceptor from '@/common/http.interceptor.js'
Vue.use(httpInterceptor)
// 引入多语言配置
import i18n from '@/common/i18n/index.js'
// 将 i18n 挂载到 Vue 原型上
Vue.prototype.$i18n = i18n
// 添加全局语言更新机制 - 优化版本
Vue.mixin({
computed: {
// 全局语言计算属性
$currentLanguage() {
return this.$i18n.getCurrentLanguage();
}
},
watch: {
// 监听全局语言变化 - 只在必要时更新
$currentLanguage(newVal, oldVal) {
if (newVal !== oldVal) {
// 只在语言真正改变时才更新
this.$nextTick(() => {
if (this.updateDeviceList) {
this.updateDeviceList();
}
});
}
}
},
mounted() {
// 监听语言变化事件 - 优化版本
uni.$on('languageChanged', (lang) => {
console.log('全局语言变化事件:', lang);
// 使用 nextTick 确保在下一个 tick 更新
this.$nextTick(() => {
if (this.updateDeviceList) {
this.updateDeviceList();
}
});
});
},
beforeDestroy() {
// 移除事件监听
uni.$off('languageChanged');
}
});
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif