title: Taro.setTopBarText(option)

sidebar_label: setTopBarText

动态设置置顶栏文字内容。只有当前小程序被置顶时能生效,如果当前小程序没有被置顶,也能调用成功,但是不会立即生效,只有在用户将这个小程序置顶后才换上设置的文字内容.

注意

  • 调用成功后,需间隔 5s 才能再次调用此接口,如果在 5s 内再次调用此接口,会回调 fail,errMsg:”setTopBarText: fail invoke too frequently”

参考文档

类型

  1. (option: Option) => Promise<CallbackResult>

参数

Option

参数 类型 必填 说明
text string 置顶栏文字
complete (res: CallbackResult) => void 接口调用结束的回调函数(调用成功、失败都会执行)
fail (res: CallbackResult) => void 接口调用失败的回调函数
success (res: CallbackResult) => void 接口调用成功的回调函数

示例代码

  1. Taro.setTopBarText({
  2. text: 'hello, world!'
  3. })

API 支持度

API 微信小程序 H5 React Native
Taro.setTopBarText ✔️