Skip to main content
Version: Next

Taro.setTopBarText(option)

Dynamically sets the text in the top bar. The content takes effect only when the current Mini Program is sticky on top. Otherwise, the call can succeed but the settings will not take effect until the Mini Program is sticky on top.

Note

  • When this API is successfully called, you must wait for at least 5 seconds to call it again. Otherwise, the callback will fail, and an errMsg of "setTopBarText: fail invoke too frequently" will appear.

Reference

Type

(option: Option) => Promise<CallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
textstringYesThe text in the top bar
complete(res: CallbackResult) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: CallbackResult) => voidNoThe callback function for a failed API call
success(res: CallbackResult) => voidNoThe callback function for a successful API call

Sample Code

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

API Support

APIWeChat Mini-ProgramH5React Native
Taro.setTopBarText✔️