zoukankan      html  css  js  c++  java
  • vue +antd 动态表单

    先说下效果:

     代码:

    <template>
      
      <div>
        <a-card title="form-data" :bordered="true" style=" 40%">
    
          <div>
            <a-form ref="form" layout="inline" :model="form" >
              <div v-for="(item, index) in form.dynamicItem" :key="index">
                    <a-form-item
                    label="key"
                    :prop="'dynamicItem.' + index + '.key'"
                    :label-col="formItemLayout.labelCol"
                    :wrapper-col="formItemLayout.wrapperCol"
                  >
                    <a-input v-model="item.key"></a-input>
                  </a-form-item>
            
                    <a-form-item
                    label="value"
                    :prop="'dynamicItem.' + index + '.value'"
                    :label-col="formItemLayout.labelCol"
                    :wrapper-col="formItemLayout.wrapperCol"
                  >
                    <a-input v-model="item.value"></a-input>
                  </a-form-item>
                  <a-form-item>
                    <a-icon v-if="index !== 0" @click="deleteItem(item, index)"  class="dynamic-delete-button"
                      type="minus-circle-o"></a-icon>
                  </a-form-item>
              </div>
            </a-form>
      
            <div style="display: flex; justify-content: center;">
              <a-button type="dashed"  @click="addItem" >
                <a-icon type="plus" /> Add field
              </a-button>
            </div>
          </div>
    
        </a-card>
      </div>
    
    </template>
    
    
    <script>
        const columns = [
        {
          title: 'Key',
          dataIndex: 'Key',
           '10%',
          scopedSlots: { customRender: 'Key' },
        },
        {
          title: 'Value',
          dataIndex: 'value',
           '10%',
          scopedSlots: { customRender: 'value' },
        },
        {
          title: 'desc',
          dataIndex: 'desc',
           '20%',
          scopedSlots: { customRender: 'desc' },
        },
        {
          title: 'operation',
          "4%",
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operation' },
        },
      ];
      
    
      export default{
    
    
          computed: {
            
              formItemLayout() {
                const { formLayout } = this;
                return{
                  
                      labelCol: { span: 5},
                      wrapperCol: { span: 19 }
                    } 
              }
                 },
        data () {
          return {
            form: {
              // index:0,
            dynamicItem: [
              {
                key: "",
                value: ""
              }
            ]
          },
    
          }
        },
        //methods 
    
        methods: {
          
          addItem() {
          this.form.dynamicItem.push({
            key: "",
            value: ""
          });
        },
        sure(form) {
          console.log(this.form.dynamicItem.length, "length");
          this.$refs[form].validate(valid => {
            if (valid) {
              alert("submit!");
            } else {
              console.log("error submit!!");
              return false;
            }
          });
        },
        deleteItem(item, index) {
          this.form.dynamicItem.splice(index, 1);
          console.log(this.form.dynamicItem, "删除");
        },
    
        }
    
      }
      
    </script>
    

      

     

  • 相关阅读:
    Android之退出整个应用方法
    自定义popupwindow(解决位置控制困惑)
    日期格式转换
    简单用于测试的listview的视图
    复制res下文件进sd卡
    自定义九宫格式的弹出menu
    动画隐藏或者显示控件
    截取p3片段
    微信几种动画进入退出应用
    codeforce Round On Sum of Fractions + stl 的应用
  • 原文地址:https://www.cnblogs.com/SunshineKimi/p/14741527.html
Copyright © 2011-2022 走看看