(精华2020年5月21日更新) vue实战篇 缓存页面的强制更新

页面缓存后,页面是不会变化的。要使缓存页面变化可以利用路由的钩子函数beforeRouteLeave。

<template>
  <div
  </div>
</template>
<script>
export default {
     
  methods: {
     
  },
  beforeRouteLeave(to, from, next) {
     
    // 导航离开该组件的对应路由时调用
    // 可以访问组件实例 `this`
    console.log(to);
    if (to.name !== "myQuestionDetail") {
     
      this.getQuestionList();
    }
    next();
  },
  mounted() {
     
    this.getQuestionList();
  }
};
</script>

你可能感兴趣的:((持续更新)vue实战篇,vue.js)