vue强制更新页面方法总结

发布于 2020-01-22  93 次阅读


1.强制更新,当数据改变了而页面没有改变

this.$set()

this.$forceUpdate()

this.$set()

this.$forceUpdate()

2.watch监听路由,当路由发生变化时,页面没有刷新,可以监听他的路由,当路由发生变化时,刷新页面或者触发动作,使得整个页面刷新

  watch: {
    $route: {
      handler(newVal, oldVal) {
        if (newVal.query.code !== oldVal.query.code)
        或者
        
        newVal.params.id !== odl.params.id
        {
          //调用组价
          // this.$emit("");
          //执行函数
          //this.bindwx();
        }
      }
    }
  }
  
  

子路由触发父路由的方法,如果有多层路由,需要由子路由发出动作再一层一层的传上去,
如孙子路由 this.$emit("updatekeyFn");

<view-router @updatekeyFn="updatekeyFn()"/>
<view-router @updatekeyFn="updatekeyFn()"/>


一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。