HomeDocs
Skip to main content

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

PropertyTypeDefaultRequiredDescription
indexnumberYesThe 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.
textstringYesThe text displayed on the tab button.
iconPathstringYesThe 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".
selectedIconPathstringYesThe 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".
successfunctionNoThe callback function for a successful API call.
failfunctionNoThe callback function for a failed API call.
completefunctionNoThe callback function that is called when the API call ends (whether it succeeds or fails).

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
successstringtrue - Success

object.fail Callback Function

Parameters

Object res

PropertyTypeDescription
successstringfalse - Failure
errMsgstringError 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.

Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.