Vue 父子組件表單同步校驗


子組件代碼

// 子組件
validateForm() {
  return new Promise((resolve, reject) => {
    this.$refs.contractBaseRef.validate((valid) => {
      if (valid) {
        resolve(this.getFormData())
      } else {
        this.$message.error('請完成必填項輸入!')
          resolve(false)
      }
  })
 })

子組件代碼

// 父組件
<template>
  <contract-base-edit ref="outBaseInfoRef" />
</template>
<script>
// methods
this.$refs['outBaseInfoRef'].validateForm().then(res => {
  console.info('res out', res)
})
</script>


免責聲明!

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



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