已为小白,啥都不懂
2022-01-20 09:28
采纳率: 98%
浏览 80
已结题

初次使用Checkbox 多选框,如何将已有的select下拉框修改成checkbox多选框

自己尝试的跟着element组件学习着写,但是由于技术有限,出现了以下几点bug
1.打开页面时,无法回显已选择的

img

2.全选按钮失效没作用

代码如下:

img

img

我想将点位的select下拉框修改成checkbox复选框

 <el-form-item label="点位" prop="dw_value">
                    <el-select v-model="ruleForm.dw_value" multiple filterable  placeholder="请选择" size="small"
                        class="widthfix">
                        <el-option v-for="item in dw_options" :key="item.id" :label="item.dwmc"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>

                <template>
                    <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选
                    </el-checkbox>
                    <div style="margin: 15px 0;"></div>
                    <el-checkbox-group v-model="ruleForm.dw_value" @change="handleCheckedCitiesChange">
                        <el-checkbox v-for="item in dw_options" :label="item.dwmc" :key="item.id" :value="item.id">
                        </el-checkbox>
                    </el-checkbox-group>
                </template>



 handleCheckAllChange(val) {
                let that = this
                this.ruleForm.dw_value = val ? that.dw_options : [];
                this.isIndeterminate = false;
            },
            handleCheckedCitiesChange(value) {
                let checkedCount = value.length;
                this.checkAll = checkedCount === this.dw_options.length;
                this.isIndeterminate = checkedCount > 0 && checkedCount < this.dw_options.length;
            },

3条回答 默认 最新

相关推荐 更多相似问题