uniapp动态修改样式_uniapp 动态设置 tabBar 的整体样式

uni.setTabBarItem(OBJECT)

动态设置 tabBar 某一项的内容

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

x

OBJECT参数说明:

属性

类型

默认值

必填

说明

index

number

tabBar 的哪一项,从左边算起

text

String

tab 上的按钮文字

iconPath

String

图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效,不支持网络图片

selectedIconPath

String

选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效

success

Funtion

接口调用成功的回调函数

fail

Funtion

接口调用失败的回调函数

complete

Funtion

接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

uni.setTabBarItem({

index: 0,

text: 'text',

iconPath: '/path/to/iconPath',

selectedIconPath: '/path/to/selectedIconPath'

})

uni.setTabBarStyle(OBJECT)

动态设置 tabBar 的整体样式

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

x

OBJECT参数说明:

属性

类型

默认值

必填

说明

color

String

tab 上的文字默认颜色,HexColor

selectedColor

String

tab 上的文字选中时的颜色,HexColor

backgroundColor

String

tab 的背景色,HexColor

borderStyle

String

tabBar上边框的颜色, 仅支持 black/white

success

Funtion

接口调用成功的回调函数

fail

Funtion

接口调用失败的回调函数

complete

Funtion

接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

uni.setTabBarStyle({

color: '#FF0000',

selectedColor: '#00FF00',

backgroundColor: '#0000FF',

borderStyle: 'white'

})

uni.hideTabBar(OBJECT)

隐藏 tabBar

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

x

OBJECT参数说明:

属性

类型

默认值

必填

说明

animation

boolean

false

是否需要动画效果,仅微信小程序和百度小程序支持

success

Funtion

接口调用成功的回调函数

fail

Funtion

接口调用失败的回调函数

complete

Funtion

接口调用结束的回调函数(调用成功、失败都会执行)

uni.showTabBar(OBJECT)

显示 tabBar

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

x

OBJECT参数说明:

属性

类型

默认值

必填

说明

animation

boolean

false

是否需要动画效果,仅微信小程序和百度小程序支持

success

Funtion

接口调用成功的回调函数

fail

Funtion

接口调用失败的回调函数

complete

Funtion

接口调用结束的回调函数(调用成功、失败都会执行)

uni.setTabBarBadge(OBJECT)

为 tabBar 某一项的右上角添加文本。

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

x

OBJECT参数说明:

参数

类型

必填

说明

index

Number

tabBar的哪一项,从左边算起

text

String

显示的文本,不超过 3 个半角字符

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

uni.setTabBarBadge({

index: 0,

text: '1'

})

uni.removeTabBarBadge(OBJECT)

移除 tabBar 某一项右上角的文本。

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

x

OBJECT参数说明:

参数

类型

必填

说明

index

Number

tabBar的哪一项,从左边算起

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

uni.showTabBarRedDot(OBJECT)

显示 tabBar 某一项的右上角的红点。

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

x

OBJECT参数说明:

参数

类型

必填

说明

index

Number

tabBar的哪一项,从左边算起

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

uni.hideTabBarRedDot(OBJECT)

隐藏 tabBar 某一项的右上角的红点。

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

x

OBJECT参数说明:

参数

类型

必填

说明

index

Number

tabBar的哪一项,从左边算起

success

Function

接口调用成功的回调函数

fail

Function

接口调用失败的回调函数

complete

Function

接口调用结束的回调函数(调用成功、失败都会执行)

uni.onTabBarMidButtonTap(CALLBACK)

监听中间按钮的点击事件

平台差异说明

App

H5

微信小程序

支付宝小程序

百度小程序

头条小程序

QQ小程序

√(HBuilderX 2.3.4+)

x

x

x

x

x

x

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UniApp中,我们可以使用动态设置的方式来修改Tabbar样式和内容。 一、修改Tabbar样式: 1. 在App.vue文件中,添加一个全局的tabbar样式变量,例如: ```javascript export default { globalData: { tabBarStyle: { backgroundColor: '#ffffff', color: '#000000', selectedColor: '#ff0000', borderStyle: 'white', list: [ { pagePath: 'pages/index/index', text: '首页', iconPath: 'static/tabBar/home.png', selectedIconPath: 'static/tabBar/home_selected.png' }, { pagePath: 'pages/category/category', text: '分类', iconPath: 'static/tabBar/category.png', selectedIconPath: 'static/tabBar/category_selected.png' }, // 其他tabbar项... ] } } } ``` 2. 在页面的onLoad钩子函数中,动态修改tabbar样式: ```javascript onLoad() { this.globalData.tabBarStyle.backgroundColor = '#f5f5f5'; this.globalData.tabBarStyle.color = '#666666'; this.globalData.tabBarStyle.selectedColor = '#ff9900'; } ``` 3. 修改样式后,通过this.globalData.tabBarStyle.list属性可以获取到tabbar的列表数据,根据实际需要修改每个tabbar项的页面路径、文字、图标等。 二、修改Tabbar内容: 1. 在页面的onLoad钩子函数中,动态修改tabbar的内容: ```javascript onLoad() { this.globalData.tabBarStyle.list[0].text = 'New首页'; this.globalData.tabBarStyle.list[0].iconPath = 'static/tabBar/home_new.png'; this.globalData.tabBarStyle.list[0].selectedIconPath = 'static/tabBar/home_selected_new.png'; } ``` 2. 修改完内容后,可以通过this.globalData.tabBarStyle.list属性获取到每个tabbar项的具体内容,并进行修改。 通过以上方式,我们可以实现在UniApp动态设置Tabbar样式和内容。如果需要实时更新Tabbar样式和内容,可以通过监听数据变化,动态更新页面显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值