vue 父组件调用子组件方法,子组件页面值不自动更新

子组件中需要watch监听被调用方案,对变动的值重新赋值即可,代码如下:

父组件:

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

子组件:

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

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

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