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>