useLaunchOptions
获取小程序启动时参数(仅小程序端可用)
何时使用
当要对小程序启动时做参数判断时
API
const launchOptions = useLaunchOptions();
返回值说明
返回值 | 说明 | 类型 |
---|---|---|
launchOptions | 启动参数 | LaunchAppOptions |
代码演示
- React
- Vue
wechat/useLaunchOptions/index
import React from 'react';
import { useLaunchOptions } from 'taro-hooks';
import DemoContent from '@src/components/DemoContent';
import { Cell } from '@taroify/core';
export default () => {
const launchOptions = useLaunchOptions();
return (
<DemoContent>
{Object.keys(launchOptions).length ? (
<Cell.Group clickable>
{Object.entries(launchOptions).map(([key, value]) => (
<Cell key={key} title={key}>
{JSON.stringify(value)}
</Cell>
))}
</Cell.Group>
) : (
<Cell>暂无信息</Cell>
)}
</DemoContent>
);
};
wechat/useLaunchOptions/index
<template>
<demo-content>
<nut-cell-group>
<nut-cell
v-for="(value, key) in launchOptions"
:key="key"
:title="key"
:desc="value"
></nut-cell>
</nut-cell-group>
</demo-content>
</template>
<script setup lang="ts">
import { useLaunchOptions } from 'taro-hooks';
const launchOptions = useLaunchOptions();
</script>
Hook 支持度
微信小程序 | H5 | ReactNative |
---|---|---|
✔️ |