获取首次启动时的参数。返回值与App.onLaunch的回调参数一致
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS |
|---|---|---|---|---|---|
| 4.0 | 4.41 | 3.91 | 4.11 | 3,0 | 4.61 |
| 类型 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OnLaunchOptions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
示例
<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({
checked: false,
// #ifdef VUE3-VAPOR && !APP-HARMONY
homePagePath: 'pages/tabBar/tab-bar',
// #endif
// #ifdef !VUE3-VAPOR || APP-HARMONY
homePagePath: 'pages/tabBar/component',
// #endif
launchOptionsPath: '',
launchOptionsString: '',
testResult: false
} as DataType)
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>
获取本次启动时的参数。返回值与App.onShow的回调参数一致
uni.getEnterOptionsSync 和 uni.getLaunchOptionsSync 的区别,相当于应用的 onShow 和 onLaunch 的区别,详见应用生命周期
| Web | 微信小程序 | Android | iOS | HarmonyOS 系统版本 | HarmonyOS |
|---|---|---|---|---|---|
| 4.0 | 4.41 | 4.25 | 4.25 | 3,0 | 4.61 |
| 类型 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OnShowOptions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
示例
<template>
<page-head title="getEnterOptionsSync"></page-head>
<view class="uni-padding-wrap">
<view class="uni-common-mt">
<text>应用本次启动路径:</text>
<text style="margin-top: 5px">{{ data.enterOptionsString }}</text>
</view>
</view>
</template>
<script setup lang="uts">
import { state } from '@/store/index.uts'
type DataType = {
enterOptionsString: string,
testResult: boolean,
}
// Data
const data = reactive({
enterOptionsString: '',
testResult: false,
} as DataType)
// Lifecycle
onReady(() => {
const appShowOptions = state.globalData.showOptions
const enterOptions = uni.getEnterOptionsSync()
data.enterOptionsString = JSON.stringify(enterOptions, null, 2)
data.testResult = (enterOptions.path == appShowOptions.path && enterOptions.appScheme == appShowOptions.appScheme && enterOptions.appLink == appShowOptions.appLink)
})
defineExpose({
data
})
</script>
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| errMsg | string | 是 | 错误信息 |