vue什麼情況下需要用到this.$nextTick

MayDo發表於2018-12-07
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之後


相關文章