vue ant 验证 获取 设置 重置 错误

<template>

  <a-form @submit="handleOk" :form="form">

    <!-- form="form" 必须优先注册  -->

    <!-- 客户姓名 -->

 

    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="客户姓名:">

      <a-input

        v-decorator="[

          'name', 

         // 给表单赋值或拉取表单时,该input对应的key  

          {rules: [{ required: true, message: '请输入客户名称!' }]}

        ]"

        placeholder="请输入客户名称"

      />

    </a-form-item>

 

    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="客户地址:">

      <a-input

        v-decorator="[

          'address', 

         // 给表单赋值或拉取表单时,该input对应的key  

          {rules: [{ required: true, message: '请输入客户地址!' }]}

        ]"

        placeholder="请输入客户地址"

      />

    </a-form-item>

 

    <a-button @click="Freset">清空表单</a-button>

    <a-button @click="Fset">赋值</a-button>

    <a-button @click="FsetErr">赋err值</a-button>

    <a-button @click="Fget">获取值</a-button>

    <a-button @click="Fvalidate">验证</a-button>

  </a-form>

</template>

 

<script>

 

 

export default {

  name: "TestForm",

  data() {

    return {

      form: this.$form.createForm(this) // 只有这样注册后,才能通过表单拉取数据

    };

  },

  methods: {

    Freset() {

      this.form.resetFields();

    },

    Fset() {

      this.form.setFieldsValue({

        name: "设置值"

      });

    },

    FsetErr() {

     

     const arr = [

        {

          message: "您输入的格式不正确!",

          field: "name"

        }

      ];

 

      this.form.setFields({

        name: { value: "错误信息", errors: arr }

      });

    },

 

    Fget() {

      alert(JSON.stringify(this.form.getFieldsValue()));

    },

 

    Fvalidate() {

      this.form.validateFields((err, values) => {

        if (!err) {

          alert(JSON.stringify(values));

        }

      });

    }

  }

};

</script>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值