文件
OmniCard/mpuniapp/pages/API/get-launch-options-sync/get-launch-options-sync.uvue

64 行
1.7 KiB
Plaintext

<template>
<page-head title="getLaunchOptionsSync"></page-head>
<view class="uni-padding-wrap">
<button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
<view class="uni-common-mt">
<text>应用本次启动路径:</text>
<text style="margin-top: 5px">{{ data.launchOptionsPath }}</text>
</view>
<view class="uni-common-mt">
<text>应用本次启动:</text>
<text style="margin-top: 5px">{{ data.launchOptionsString }}</text>
</view>
</view>
</template>
<script setup lang="uts">
import { state } from '@/store/index.uts'
type DataType = {
checked: boolean;
homePagePath: string;
launchOptionsPath: string;
launchOptionsString: string;
testResult: boolean;
}
const data = reactive<DataType>({
checked: false,
homePagePath: 'pages/tabBar/component',
launchOptionsPath: '',
launchOptionsString: '',
testResult: false
})
const compareOnLaunchRes = () => {
const launchOptions = uni.getLaunchOptionsSync();
data.launchOptionsString = JSON.stringify(launchOptions, null, 2)
const appLaunchOptions = state.globalData.launchOptions
const isPathSame = launchOptions.path == appLaunchOptions.path
const isAppSchemeSame = launchOptions.appScheme == appLaunchOptions.appScheme
const isAppLinkSame = launchOptions.appLink == appLaunchOptions.appLink
data.testResult = isPathSame && isAppSchemeSame && isAppLinkSame
}
const getLaunchOptionsSync = () => {
const launchOptions = uni.getLaunchOptionsSync()
data.launchOptionsPath = launchOptions.path
if (launchOptions.path == data.homePagePath) {
data.checked = true
}
}
onReady(() => {
compareOnLaunchRes()
})
defineExpose({
data,
getLaunchOptionsSync
})
</script>