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

2021-10-12  本文已影响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)
                    }
                }



            },
上一篇下一篇

猜你喜欢

热点阅读