vue 父組件調用子組件方法,子組件頁面值不自動更新

子組件中需要watch監聽被調用方案,對變動的值重新賦值即可,代碼如下:

父組件:

<CommentReply ref="child"></CommentReply>
this.$refs.child.getComment();

子組件:

watch: {
    comments: function(newValue, oldValue) {
      this.getComment();
    }
  },

注意:以上 comments 是子組件中被更新的值;getComment()是 父組件調用子組件的方法。

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