ant-design-vue——select下拉框tags清空已选数据

Posted linjiangxian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ant-design-vue——select下拉框tags清空已选数据相关的知识,希望对你有一定的参考价值。

我的需求: select下拉联动,选择模板配置后,字段配置重新获取,此时要清空之前已选的字段

 

代码:

<template>
    <div>
         <a-form class="dataForm" :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 19 }"
                    @submit="handleCancel">
<a-form-item label="模板配置" v-model="osType">
                    <a-row :gutter="16">
                        <a-col class="gutter-row" :span="22">
                            <a-select
                                    placeholder="请选择"
                                    style="width: 100%"
                                    v-decorator="[‘osType‘,rules.osType]"
                                    @change="changeOsType"
                            >
                                <a-select-option v-for="(item,index ) in modeListArr" :key="index" :value="item.key">
                                    {{ item.value }}
                                </a-select-option>
                            </a-select>
                        </a-col>
                        <a-col class="gutter-row" :span="2">
                            <a-icon type="question-circle" />
                        </a-col>
                    </a-row>
                </a-form-item>
     <a-form-item label="字段配置" v-model="fieldList">
                    <a-select
                            mode="tags"
                            placeholder="请选择"
                            style="width: 100%"
                            v-decorator="[‘fieldList‘, rules.fieldList]"
                    >
                        <a-select-option v-for="(item,index ) in fieldListArr" :key="index" :value="item.key">
                            {{ item.value }}
                        </a-select-option>
                    </a-select>
                </a-form-item>
            </a-form>
  </div>
</template>

<script>
    export default {
        data() {
            return {
               osType:‘‘,
               modeListArr:[],
               fieldList: ‘‘,
               fieldListArr: [],// 配置列表,
               form: this.$form.createForm(this), 
               rules: {
                    osType: {
                        rules: [
                            {
                                required: true,
                                message: "请选择",
                            }],
                        initialValue: [],
                    },
                    fieldList: {
                        rules: [
                            {
                                required: true,
                                message: "请选择",
                            }],
                        initialValue: [],
                    },
                }
            }
        },
        mounted(){
            let that = this;
        // ···请求接口并处理 ···     that.rules[
‘fieldList‘].initialValue = [‘111‘]; //初始化示例
        // ···
}, methods: { changeOsType(e) { let that = this; that.osType = e; that.form.setFieldsValue({ //《=关键 清空tag选项 ‘fieldList‘: [] }) that.fieldList = []; that.fieldListArr = []; },
       handleCancel(){
          ···
       }
  } 
}
</script>

 

以上是关于ant-design-vue——select下拉框tags清空已选数据的主要内容,如果未能解决你的问题,请参考以下文章

html下拉框 select

select 下拉框 不可选

select下拉框、输入框在IOS中出现阴影

如何在select下拉框设置滚动条

下拉框select的值保存不生效

如何获取select下拉框的值