dlt.setTabBarItems
Introduction
Batch dynamically set the content of 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 |
---|---|---|---|---|
tabs | tabItem[] | Yes | Batch update tabBar information. The batch data here needs to have the same size and content as the tabs list in appConfig . Otherwise, it won't take effect. All images in a group of data need to be filled out to take effect. | |
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). |
tabItem Explanation
Property | Type | Default | Required | Description |
---|---|---|---|---|
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". |
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({
setTabBarItems() {
dlt.setTabBarItems({
tabs: [
{ text: '', iconPath: '', selectedIconPath: '' },
{
text: 'tab2',
iconPath: 'http://xxx.png',
selectedIconPath: 'http://xyx.png',
},
],
success: () => {
console.log('success');
},
});
},
});
In the sample code provided, dlt.setTabBarItems
is used to batch dynamically set the content of the tabBar. You need to specify an array of tabItem
objects, where each object represents the content of a tab. Each tabItem
object should include the text, iconPath, and selectedIconPath properties. When the operation is successful, the success callback function is called, and it logs "success" to the console.