在使用Nuxt vue-property-decorator typescript時,父組件調用子組件的方法

不使用以上技術時我們一般是使用ref


<Son ref="son" />


 methods:{
      parentMethod() {
        console.log(this.$refs.son) //返回的是一個vue對象,所以可以直接調用其方法
        this.$refs.son.childMethod(this.flag); 
      }
    }

使用以上技術的情況下

(this.$refs.son as any).childMethod()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章