W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
解釋:動態(tài)設(shè)置 tabBar 某一項的內(nèi)容
Object object
屬性名 | 類型 | 必填 | 默認值 | 說明 | ||
---|---|---|---|---|---|---|
index |
Number |
是 |
tabBar 的哪一項,從左邊算起。 |
|||
text |
String |
否 |
tab 上按鈕文字 |
|||
iconPath |
String |
否 |
圖片絕對路徑,icon 大小限制為 40KB,建議尺寸為 81px * 81px,當(dāng) position 為 top 時,此參數(shù)無效,不支持網(wǎng)絡(luò)圖片。 |
|||
selectedIconPath |
String |
否 |
選中時的圖片的絕對路徑,icon 大小限制為 40KB,建議尺寸為 81px * 81px ,當(dāng) |
|||
success |
Function |
否 |
接口調(diào)用成功的回調(diào)函數(shù) |
|||
fail |
Function |
否 |
接口調(diào)用失敗的回調(diào)函數(shù) |
|||
complete |
Function |
否 |
接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行) |
代碼示例 1 - 基本示例
<view class="wrap">
<button type="primary" bindtap="customItem">
{{ !hasCustomedItem ? '自定義Tab信息' : '移除自定義信息' }}
</button>
</view>
代碼示例 2 - 切換 tab 時變化文案
Page({
onTabItemTap(item) {
console.log('點擊第幾項', item.index);
if (item.index == 1) {
this.setTabBarItem(item.index)
}
console.log('點擊tab對應(yīng)的路徑', item.pagePath);
console.log('點擊tab對應(yīng)的文本', item.text);
},
setTabBarItem(index) {
swan.setTabBarItem({
index: index,
text: '替換文本',
iconPath: '/images/component_normal.png',
selectedIconPath: '/images/component_selected.png',
success: () => {
console.log('setTabBarItem success');
},
fail: err => {
console.log('setTabBarItem fail', err);
}
});
}
// 如需更多自定義底部tabBar樣式,請參考swan.setTabBarStyle示例(https://smartprogram.baidu.com/docs/develop/api/show/tabbar_swan-setTabBarStyle/)
});
錯誤碼 | 說明 |
---|---|
1001 | 執(zhí)行失敗 |
錯誤碼 | 說明 |
---|---|
202 | 解析失敗,請檢查參數(shù)是否正確。 |
1002 | 超過 icon 文件最大值 |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: