浏览代码

优化,页面报错时,刷新增加刷新页面功能

t_finder 6 月之前
父节点
当前提交
6a6101e58a
共有 1 个文件被更改,包括 24 次插入4 次删除
  1. 24 4
      layouts/error.vue

+ 24 - 4
layouts/error.vue

@@ -3,10 +3,13 @@
     <h1 v-if="error.statusCode === 404">
       {{ pageNotFound }}
     </h1>
-    <h1 v-else>
-      {{ otherError }}
-    </h1>
-    <NuxtLink to="/"> Home page </NuxtLink>
+    <div v-else>
+      <h1>
+        {{ otherError }}
+      </h1>
+      <van-button type="primary" @click="refreshPage">主要按钮</van-button>
+    </div>
+    <!-- <NuxtLink to="/"> Home page </NuxtLink> -->
   </div>
 </template>
 
@@ -27,12 +30,29 @@ export default {
     };
   },
   head() {
+    console.log('tempErr',this.error)
     const title =
       this.error.statusCode === 404 ? this.pageNotFound : this.otherError;
     return {
       title,
     };
   },
+  methods: {
+    // 刷新页面
+    refreshPage() {
+      const currentPath = this.$route.path;
+      const queryParams = this.$route.query;
+
+      // 添加一个随机参数以确保刷新
+      this.$router.replace({
+        path: currentPath,
+        query: {
+          ...queryParams,
+          _refresh: Date.now()
+        }
+      });
+    }
+  }
 };
 </script>