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