HomeDocs
Skip to main content

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

PropertyTypeDefaultRequiredDescription
tabstabItem[]YesBatch 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.
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).

tabItem Explanation

PropertyTypeDefaultRequiredDescription
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".

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({
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.

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