Ant Design Vue 通過v-decorator實現數據綁定


        <a-form-item label="切換環境">
          <a-select
            v-decorator="[
              'env',
              { rules: [{ required: true, message: '該字段是必填字段' }] }
            ]"
            placeholder="請選擇環境"
          >
            <a-select-option value="dev">dev</a-select-option>
            <a-select-option value="test">test</a-select-option>
            <a-select-option value="staging">staging</a-select-option>
          </a-select>
        </a-form-item>

env就是綁定的值

如何查看 from 中綁定的表單數據?

  data() {
    return {
      form: this.$form.createForm(this, { name: 'coordinated' })
    }
  },
  methods: {
    handleSubmit(e) {
      e.preventDefault()
      this.form.validateFields(async (err, values) => {
        const checkMailParams = { ...values }
        delete checkMailParams.env
        if (!err) {
          const { response } = await CheckMailBox(checkMailParams)
          if (response) {
            this.text = response
          } else {
            this.$message.error(`請求異常`, 2)
          }
        }
      })
    },

必須先對form進行注冊 this.$form.createForm(this, { name: 'coordinated' })

this.form.validateFields 方法就可以獲取表單里的值 此時 打印的 values 就是 當前form表單里的全部數據 了

如果提交表單,不用提交form表單里的全部數據,需要過濾某個值,可以使用

    const checkMailParams = { ...values }
    delete checkMailParams.env


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM