tabs

发布时间 2023-10-21 23:39:24作者: 樱花馆长
<view class="tabs">
    <view class="tabsitem {{sindex==index?'active':''}}" data-index="{{index}}" bindtap="bindtap" wx:for="{{array}}">{{item}}</view>
</view>
Component({
  properties: {
    array: {
      type: Array,
      value: []
    }
  },
  data: {
    sindex: 0
  },
  methods: {
    bindtap(e) {
      let sindex = e.currentTarget.dataset.index
      console.log("sindex", e);
      this.setData({
        sindex
      }) 
      this.triggerEvent('myevent', sindex)
    }
  }
})
.tabs{
  display: flex;
}
.tabsitem{
  flex: 1;
  text-align: center;
  height: 60rpx;
  line-height: 60rpx;

}
.active{
  color: red;
  border-bottom: 2rpx solid red;
}