調用子組件中的方法,明明定義了還報“Cannot read properties of undefined (reading 'fullValidEvent')”


在修改頁面,在父組件中直接調用子組件中的方法,通過ref來調用。明明在子組件中定義了這個方法,還一直報undefined

if (this.form.receivingType == 0) {
          await this.$refs.editTable1.fullValidEvent()
        } else if (this.form.receivingType == 1) {
          await this.$refs.editTable2.fullValidEvent()
        } else if (this.form.receivingType == 2) {
          await this.$refs.editTable3.fullValidEvent()
        }

image

我就嘗試先確定存在這個組件才調用這個方法,果然這樣可以

if (this.form.receivingType == 0) {
          this.$refs['editTable1'] && await this.$refs['editTable1'].fullValidEvent()
        } else if (this.form.receivingType == 1) {
          this.$refs['editTable2'] && await this.$refs['editTable2'].fullValidEvent()
        } else if (this.form.receivingType == 2) {
          this.$refs['editTable3'] && await this.$refs['editTable3'].fullValidEvent()
        }


免責聲明!

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



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