(精华)2020年7月19日 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>

猜你喜欢

转载自blog.csdn.net/aa2528877987/article/details/107440552