解决uniapp的checkBox取消选中

<checkbox-group @change="selectUniverSity" checked>
		 <checkbox v-for="(item,index) in universityTypes" 
				 class="m-2"
				 :key="item.typeId"
				 :value="item.typeId" 
                <!--每次触发一次多选则向checkUnType追加一次,使用includes判断如果当前typeId包含在此数组则为true从而控制选中,否则取消选中-->
                :checked="checkUnType.includes(String(item.typeId))">
				 {{item.name}}
		</checkbox>
</checkbox-group>

data(){

    return{
        universityList:[
            {typeId:'',name:'不限' },
            {typeId:'12',name:'哈呵呵'},
            {typeId:'13',name:'哈嘿嘿'},
            {typeId:'14',name:'哈呼呼'},
            {typeId:'15',name:'哈拉拉'}
        ],
        checkUnType:[]
    }
},

methods:{
     //我的需求是点击当前多选框中的不限,其他选框取消选中,点击其他选框不限选框取消选择
    selectUniverSity(val){
				let zhi=false;
                //(2)但是选择非不限内容时需首先判断之前checkUnType的值是否数组长度为1且为空 
				if(this.checkUnType.length===1&&this.checkUnType.includes('')){
					zhi=true;
				}
				this.checkUnType=[]; 
				this.checkUnType=val.detail.value;
                //(3)如果是则设置一个参数为true,将多选框中为空的一项删掉
				if(zhi){
					this.checkUnType.splice(0,1);
				}else if(val.detail.value.includes('')){
                    //(1)首先判断如果所选的checkUnType包含''这一项则设置只包含'',去掉其它
                  
					this.checkUnType=[''];
				}
                //(4)最后接收获取的值赋给条件
                if(this.checkUnType.length>0&&this.checkUnType[0]!==''){
					this.universityList=this.checkUnType;
				}
				
			},


}

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

路光.

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

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

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

打赏作者

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

抵扣说明:

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

余额充值