vue什么情况下需要用到this.$nextTick

419 阅读1分钟
ratingtypeSelect(type) {
  this.selectType = type
  this.$nextTick(() => {
    this.scroll.refresh()
  })
},
<ratingselect  @ratingtypeselect="ratingtypeSelect" :select-type="selectType"
              :ratings="food.ratings"></ratingselect>

当我们改变data里面的值(selectType)的时候,dom不能及时更新,所以还会用this.$nextTick异步更新当前组件里面之前用到的better-scroll,因为我们改变数据的时候,vue的dom更新是异步的,它会放到一个更新队列里面,当下一个时间周期也就是this.$nextTick的时候,它的dom才会更新,所以this.scroll.refresh必须要在this.$nextTick之后