以前一直用的

this.$forceUpdate()

去更新强制刷新组件

这里介绍另外一种,给当前组件绑定一个key值,如果key变化了,自然而然就会通过diff算法脏检查机制而自动刷新数据,除此之外v-if也可以刷新组件

//模版上绑定key
<SomeComponent :key="theKey"/>
//选项里绑定data
data(){
  return{
      theKey:0
  }
}
//刷新key达到刷新组件的目的
theKey++;
Last modification:April 1, 2020
If you think my article is useful to you, please feel free to appreciate