dlt.setTabBarItem
Introduction
Dynamically set the content of a specific tab in the tabBar, including text and icons. Icons can be local files or network images.
Usage Limitations
Supported in the base library version 4.0.0 or higher.
Parameters
Object object
Property | Type | Default | Required | Description |
---|---|---|---|---|
index | number | Yes | The index of the tabBar item to be modified, starting from 0 from the left. It should not exceed the size of the predefined tabs. Note: Do not exceed the range of the appConfig tabs. | |
text | string | Yes | The text displayed on the tab button. | |
iconPath | string | Yes | The path to the icon image. Icon size is limited to 40kb, and it is recommended to have dimensions of 81px * 81px. Supports network images. This parameter is invalid when the position is set to "top". | |
selectedIconPath | string | Yes | The path to the icon image when the tab is selected. Icon size is limited to 40kb, and it is recommended to have dimensions of 81px * 81px. Supports network images. This parameter is invalid when the position is set to "top". | |
success | function | No | The callback function for a successful API call. | |
fail | function | No | The callback function for a failed API call. | |
complete | function | No | The callback function that is called when the API call ends (whether it succeeds or fails). |
object.success Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | true - Success |
object.fail Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | false - Failure |
errMsg | string | Error message. Possible values are: - ok - Parameter error: T10001 - set tab item failed, it's not a tab page: T10002 - set tab item failed, please check the config: T10003 |
Sample Code
// pages/index/index.js
Page({
setTabBarItem() {
dlt.setTabBarItem({
index: 0,
text: 'tab1',
iconPath: 'http://xxx.png',
selectedIconPath: 'http://xyx.png',
success: () => {
console.log('success');
},
});
},
});
In the sample code provided, dlt.setTabBarItem
is used to dynamically set the content of a specific tab in the tabBar. You need to specify the index of the tab, the text to display, and the paths to the icon images (both regular and selected). When the operation is successful, the success callback function is called, and it logs "success" to the console.