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.
Type
(option: Option) => Promise<CallbackResult>
Parameters
Option
Property | Type | Required | Description |
---|---|---|---|
text | string | Yes | The text in the top bar |
complete | (res: CallbackResult) => void | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail | (res: CallbackResult) => void | No | The callback function for a failed API call |
success | (res: CallbackResult) => void | No | The callback function for a successful API call |
Sample Code
Taro.setTopBarText({
text: 'hello, world!'
})
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.setTopBarText | ✔️ |