Vue3+TS項目中,父組件用ref方式調用子組件方法時報錯導致編譯不通過


this.$refs.permissionModal.childMethods()

ERROR: Object is of type 'unknown'.

嘗試解決成功的一種方法:

在子組件的生命周期函數中

  mounted() {
    //將this拋給父組件,讓父組件能夠調用本組件的方法
    this.$emit('childThis', this)
  },

在父組件中

<template>
    <Child @childThis="childThisReceive"/>
</template>
    childThisReceive(childThis: any) {
      this.childThis = childThis
    },

用這種方式調用

this.childThis.childMethodsXXX()

 


免責聲明!

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



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