vue强制刷新页面

方法一
this.$router.go(0) // 会出现一段空白页,用户体验很差
方法二

在 app.vue 中定义 reload() 方法vue

<template>
  <div id="app">
    <router-view v-if="isReload"/>
  </div>
</template>
 
<script>
export default {
  name: 'App',
  provide() {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
      isReload: true
    }
  },
  methods: {
    reload() {
      this.isReload = false
      this.$nextTick(() => {
        this.isReload = true
      })
    }
  }
}
</script>

在须要强制刷新的页面引用app

<script>
export default {
  inject: ['reload'],
  methods: {
    clickReload() { // 点击以后强制刷新
       this.reload()
     }
  }
}
</script>
相关文章
相关标签/搜索