美文网首页
vue+element复选框,自定义移除指定选中项

vue+element复选框,自定义移除指定选中项

作者: 可乐_加冰_ | 来源:发表于2021-10-12 11:27 被阅读0次
     <el-form-item label="消费者权益">
                            <el-checkbox-group v-model="formOne.customer_rights_ids" @change="changeCustomerRights">
                                <el-checkbox label="1" >7天无理由退货</el-checkbox>
                                <el-checkbox label="6" >不支持7天无理由退货</el-checkbox>
                                <el-checkbox label="2">只换不修</el-checkbox>
                                <el-checkbox label="3">15天包换</el-checkbox>
                                <el-checkbox label="4">一年保修</el-checkbox>
                                <el-checkbox label="5">终身质保</el-checkbox>
                            </el-checkbox-group>
                        </el-form-item>
    
    
     data: function () {
                return {
                    fullscreenLoading:false,
                    active: 0,
                    formOne: {
                        customer_rights_ids:['1'],
                 }
    }
    
     changeCustomerRights(checked){
                    // console.log(`checked:${checked}`);
                    // console.log(this.formOne.customer_rights_ids)
                    let one_index = '-1';//7天无理由退货
                    let sex_index = '-1';//不支持7天无理由退货
                    for (let i=0;i<this.formOne.customer_rights_ids.length;i++){
                        if (this.formOne.customer_rights_ids[i] == '1'){
                            one_index = i;
                        }
                        if (this.formOne.customer_rights_ids[i] == '6'){
                            sex_index = i;
                        }
                    }
    
                    if (one_index !='-1' && sex_index !='-1'){
    
                        if (one_index > sex_index) {
                            this.formOne.customer_rights_ids.splice(sex_index, 1)
                        }
    
                        if (sex_index > one_index) {
                            this.formOne.customer_rights_ids.splice(one_index, 1)
                        }
                    }
    
    
    
                },
    

    相关文章

      网友评论

          本文标题:vue+element复选框,自定义移除指定选中项

          本文链接:https://www.haomeiwen.com/subject/mtudoltx.html