uniapp自定义顶部tabbar

该文章描述了如何在Vue.js应用中设置商品列表的排序选项。数据包括新品、销量和价格,每个选项可以通过DOM结构中的tap事件触发方法`headChange`进行切换。方法`headChange`更新当前选中项并改变排序标志(isDesc),从而实现升序或降序排列。
摘要由CSDN通过智能技术生成

1. 准备数据

headItems: [
   {
        name: '新品',
        value: '',
        isDesc:""
    },
    {
        name: '销量',
        value: 'sale',
        isDesc:""
    },
    {
        name: '价格',
        value: 'price',
        isDesc:""
    },
    {
        name: '筛选',
        value: '',
        isDesc:""
    }
]

2. DOM结构

<view class="tab head-bar">
    <view class="per" v-for="(item,index) in headItems" :class="{'active':index==current}" @tap="headChange(index,item)" :key="index">
        {{item.name}} 
        <view class="icons"  v-if="index == 1 || index == 2">
            <uni-icons  :color="item.isDesc === 1 ? '#DD524D' : '#fff'" class="icon-child" type="arrowup" size="12"></uni-icons>
            <uni-icons  :color="item.isDesc === 0 ? '#DD524D' : '#fff'" class="icon-child" type="arrowdown" size="12"></uni-icons>
        </view>
    </view>
</view>

3. 方法

headChange(index,val) {
    this.current = index;
    this.clear(index);
    if(val.isDesc == ""){
        val.isDesc = 1
    }else if(val.isDesc == 1){
        val.isDesc = 0
    }else{
        val.isDesc = 1
    }
    this.getProductList();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值