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

送分小仙女□ 提交于 2020-08-18 05:40:42

我的需求: 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>

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!