verce-vue-test 0.0.28 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/mini2.0-main/src/App.vue
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { useAppStore } from '@/stores/app'
|
|
3
|
-
|
|
4
|
-
const appStore = useAppStore()
|
|
5
|
-
|
|
6
|
-
onMounted(async () => {
|
|
7
|
-
await appStore.initNativeDetection()
|
|
8
|
-
|
|
9
|
-
// 测试环境 + 原生设备:加载 vConsole 调试面板
|
|
10
|
-
if (import.meta.env.VITE_APP_ENV === 'test' && appStore.isNative) {
|
|
11
|
-
import('vconsole').then(({ default: VConsole }) => new VConsole())
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
</script>
|
|
1
|
+
<script setup lang="ts"></script>
|
|
15
2
|
|
|
16
3
|
<template>
|
|
17
|
-
<router-view v-
|
|
4
|
+
<router-view v-slot="{ Component }">
|
|
18
5
|
<keep-alive include="Home">
|
|
19
6
|
<component :is="Component" />
|
|
20
7
|
</keep-alive>
|
package/mini2.0-main/src/main.ts
CHANGED
|
@@ -5,6 +5,7 @@ import 'vant/lib/index.css'
|
|
|
5
5
|
|
|
6
6
|
import App from './App.vue'
|
|
7
7
|
import router from './router'
|
|
8
|
+
import { useAppStore } from '@/stores/app'
|
|
8
9
|
|
|
9
10
|
const app = createApp(App)
|
|
10
11
|
const pinia = createPinia()
|
|
@@ -14,4 +15,14 @@ pinia.use(piniaPluginPersistedstate)
|
|
|
14
15
|
app.use(pinia)
|
|
15
16
|
app.use(router)
|
|
16
17
|
|
|
18
|
+
// 等待原生环境检测完成后再挂载,确保所有组件读到的 isNative 都是正确值
|
|
19
|
+
const appStore = useAppStore()
|
|
20
|
+
await appStore.initNativeDetection()
|
|
21
|
+
|
|
22
|
+
// 测试环境 + 原生设备:加载 vConsole 调试面板
|
|
23
|
+
if (import.meta.env.VITE_APP_ENV === 'test' && appStore.isNative) {
|
|
24
|
+
const { default: VConsole } = await import('vconsole')
|
|
25
|
+
new VConsole()
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
app.mount('#app')
|
|
@@ -5,12 +5,10 @@ import { whenNativeReady } from '@/core/mxApi'
|
|
|
5
5
|
* 应用级状态 Store
|
|
6
6
|
*
|
|
7
7
|
* 存放全局共享的运行时状态,不持久化。
|
|
8
|
+
* initNativeDetection 在 main.ts 挂载前调用,组件读取时值已就绪。
|
|
8
9
|
*/
|
|
9
10
|
export const useAppStore = defineStore('app', () => {
|
|
10
|
-
/**
|
|
11
|
-
const ready = ref(false)
|
|
12
|
-
|
|
13
|
-
/** 是否在原生 APP WebView 环境中(由 App.vue 初始化时检测并写入) */
|
|
11
|
+
/** 是否在原生 APP WebView 环境中 */
|
|
14
12
|
const isNative = ref(false)
|
|
15
13
|
|
|
16
14
|
/**
|
|
@@ -18,12 +16,10 @@ export const useAppStore = defineStore('app', () => {
|
|
|
18
16
|
*
|
|
19
17
|
* 等待 deviceready 事件后判断 window.MXCommon 是否存在,
|
|
20
18
|
* 浏览器环境下 3 秒超时后返回 false。
|
|
21
|
-
* 应在 App.vue onMounted 中调用,全局只需一次。
|
|
22
19
|
*/
|
|
23
20
|
async function initNativeDetection() {
|
|
24
21
|
isNative.value = await whenNativeReady()
|
|
25
|
-
ready.value = true
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
return {
|
|
24
|
+
return { isNative, initNativeDetection }
|
|
29
25
|
})
|