兼容vue3模式获取config

This commit is contained in:
RuoYi
2025-04-23 10:37:50 +08:00
parent 0ecc627938
commit fd97380edb

66
App.vue
View File

@@ -1,37 +1,39 @@
<script setup> <script setup>
import { onLaunch } from '@dcloudio/uni-app' import { onLaunch } from '@dcloudio/uni-app'
import config from './config' import { getToken } from '@/utils/auth'
import store from '@/store' import { getCurrentInstance } from "vue"
import { getToken } from '@/utils/auth'
import { getCurrentInstance } from "vue" const { proxy } = getCurrentInstance()
const { proxy } = getCurrentInstance()
onLaunch(() => { onLaunch(() => {
initApp() initApp()
}) })
// 初始化应用 // 初始化应用
function initApp() { function initApp() {
// 初始化应用配置 // 检查用户登录状态
initConfig() //#ifdef H5
// 检查用户登录状态 checkLogin()
//#ifdef H5 //#endif
checkLogin() }
//#endif
} function checkLogin() {
if (!getToken()) {
function initConfig() { proxy.$tab.reLaunch('/pages/login')
getApp().globalData.config = config }
} }
function checkLogin() {
if (!getToken()) {
proxy.$tab.reLaunch('/pages/login')
}
}
</script> </script>
<style lang="scss"> <script>
@import '@/static/scss/index.scss' import config from './config'
export default {
onLaunch: function() {
this.globalData.config = config
}
}
</script>
<style lang="scss">
@import '@/static/scss/index.scss'
</style> </style>