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>
相關文章
相關標籤/搜索