调用子组件中的方法,明明定义了还报“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