w***@qq.com
w***@qq.com
  • 发布:2019-05-28 15:37
  • 更新:2019-12-14 11:44
  • 阅读:18652

uni-app怎么实现选择多个选项并改变其样式

分类:uni-app

下面的代码h5可以实现,编译到手机端就不行了
有没有兼容的写法啊

<template>  
    <view class="container">  
<view class="list-box">  
<view class="cell" v-for="(item,index) in rList" :key="index" :class="{'cur': rSelect.indexOf(item)!=-1}" @click="rChoose(item)">  
{{item}}  
</view>  
</view>  
</view>  
</template>  
<script>  
export default {  
     data(){  
    return{  
rList:['全部','商品新增入库','普通入库','调拨入库','调拨驳回入库','盘点入库','其他入库'],  
rSelect:['全部'],  
},  
    methods:{  
    rChoose(value){  
                    if(this.rSelect.indexOf( value )!=-1){  
                            this.rSelect.splice( this.rSelect.indexOf( value), 1 );  
                    }else{  
                            this.rSelect.push(value);  
                    }  
            },  
}  
},  
</script>  
<style lang="scss" scoped>  
        .container{  
            height: 100%;  
        }  

   .list-box{  
                padding: 6upx 20upx;  
                display: flex;  
                flex-flow: row wrap;  
                align-items: center;  
                .cell{  
                    width:150upx;  
                    height: 72upx;  
                    line-height: 72upx;  
                    margin: 16upx 32upx 16upx 0;  
                    border: 1upx dotted #f5f5f5;  
                    border-radius: 8upx;  
                    text-align: center;  
                    font-size: 28upx;  
                    overflow: hidden;  
                    &:nth-child(4n){  
                        margin: 16upx 0;  
                    }  
                    &.cur{  
                        background-color: #ff6a3f;  
                        border: 1upx dotted #ff6a3f;  
                        color: #fff;  
                    }  
                }  
            }    
</style >
2019-05-28 15:37 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

试试计算属性

  • w***@qq.com (作者)

    试过计算属性也试过写成方法都不行,有没有解决方法呀,

    2019-05-31 09:13

w***@qq.com

w***@qq.com (作者) - 前端开发

在 "app-plus"中配置"usingComponents":true,用最新的编译器就可以支持这种写法了
同样也可以支持下面的写法:
<view class="cell" v-for="(item,index) in rList" :key="index" :class="[rtrues(item)]" @click="rChoose(item)">
{{item}}
</view>

rtrues(a){
return this.rSelect.includes(a) ?'cur':''
},

终究会弄懂

终究会弄懂

在 "app-plus"中配置"usingComponents":true,用最新的编译器
但在APP中还是实现不了:

<view class="rows" v-for="(item, index) in list" :key="index" :class="item.id===id ? 'row_active' : 'row_noactive'">
2***@qq.com

2***@qq.com

请问下这个问题解决了吗

9***@qq.com

9***@qq.com

可以用 v-if v-else-if v-else 根据条件判断后 分别对应不同的class名

  • 嗨哆嚒

    怎么判断? AppPlusNvue = 'APP-PLUS-NVUE',?

    2020-08-24 09:04

该问题目前已经被锁定, 无法添加新回复