小程序自定义组件可滑动切换选项卡tab-view

tab-view

可滑动切换选项卡

 基础库 1.6.0 开始支持,低版本需做兼容处理

属性类型默认值说明最低版本

tabs

Array

[]必要属性,长度不少于2,建议不多于5,文本超出tab最大宽度则显示省略三小点 

tab-center

Boolean

false

tab是否居中排列,空出左右两侧 

show-cursor

Boolean

true

是否显示tab下方的线条游标,带有切换动画 

cursor-deviate

Number0线条游标与tab文本的垂直偏离度,最小0,最大15 

cursor-width-mode

String

normal

线条游标的宽度计算模式,normal(60rpx)、title(与当前选中的标题文本等宽)、tab(每个tab等比宽) 

color

String

#888888

未选中时的tab文本和线条颜色 

selected-color

String

#333333

选中时的tab文本和线条颜色

 

tab-background-color

String

#FFFFFF

tab的背景颜色 

highlight

Boolean

true

选中的tab是否高亮显示,有字体加粗和字号变大的效果 

duration

Number

250

线条游标的动画时长

 

component-style

String

 

组件整体样式,组件的宽、高、背景可通过该属性设置 

bindpagechange

EventHandle 点击tab或左右滑动切换会触发pagechange事件,detail={"index":0,"id":"tabviewpage0","value":"文本"} 

bindscrolltobottom

EventHandle 

滚动到底部,会触发scrolltobottom事件

detail="direction":"bottom","index":0,"id":"tabviewpage0","value":"文本"

 

示例:

json 

{
  "usingComponents": {
    "tab-view": "../../components/tab-view/tab-view"
  }
}

wxml

<tab-view 
  id='mytabview' 
  tabs='{{tabs}}'
  bindpagechange="pageChangeEvent" 
  bindscrolltobottom='scrolltobottomEvent'>
  <view 
  wx:for='{{slotIds}}' 
  wx:key 
  wx:for-index='slotindex' 
  wx:for-item='slotitem' 
  slot='{{slotitem}}'>
    <view 
    class='order-item' 
    wx:for='{{[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]}}' 
    wx:key 
    wx:for-item='orderitem'>
    {{"page: " + slotindex + " --- item: " + orderitem}}
    </view>
  </view>
</tab-view>

js


Page({

  data: {
    // tabs: [],
    // tabs: ['我已报名', '我的发布'],
    // tabs: ['吕布', '赤兔马', '方天画戟'],
    // tabs: ['昨天', '今天', '明天', '后天'],
    tabs: ['全部', '待付款', '待发货', '待收货', '待评价'],
    currentIndex: 0
  },

  onLoad: function (options) {
    this.mytabview = this.selectComponent('#mytabview')
    this.setData({
      slotIds: this.mytabview.getSlotIds()
    })
  },

  pageChangeEvent: function (e) {
    console.log(e)
  },

  scrolltobottomEvent: function (e) {
    console.log(e)
  }

})

效果:

组件传送门:https://download.csdn.net/download/honiler/10628059

注:粗略地写出来,有空再补充,有什么问题的话可评论留言。

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Homilier

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值