Fe-interview: [vue] vue怎么实现强制刷新组件?

Created on 22 Jun 2019  ·  8Comments  ·  Source: haizlin/fe-interview

[vue] vue怎么实现强制刷新组件?

vue

Most helpful comment

强制重新渲染

this.$forceUpdate()

强制重新刷新某组件

//模版上绑定key
<SomeComponent :key="theKey"/>
//选项里绑定data
data(){
  return{
      theKey:0
  }
}
//刷新key达到刷新组件的目的
theKey++;

All 8 comments

$forceUpdate?

我想到的是加一个new date()

强制重新渲染

this.$forceUpdate()

强制重新刷新某组件

//模版上绑定key
<SomeComponent :key="theKey"/>
//选项里绑定data
data(){
  return{
      theKey:0
  }
}
//刷新key达到刷新组件的目的
theKey++;

v-if ?

this.$forceUpdate()
v-if

this.$nextTick(()=>{})

组价上加 key 然后改变key值

1.如果要在组件内部中进行强制刷新

  • 调用this.$forceUpdate()强制重新渲染组件

    2.如果是刷新某个子组件

  • 利用v-if指令的特性

  • 当组件的key 值变更时,会自动的重新渲染
Was this page helpful?
0 / 5 - 0 ratings