error.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <div class="flex justify-center pt-30">
  3. <h1 v-if="error.statusCode === 404">
  4. {{ pageNotFound }}
  5. </h1>
  6. <div v-else>
  7. <h1 class="text-center">
  8. {{ otherError }}
  9. </h1>
  10. <v-btn type="submit" @click="refreshPage">重新加载页面</v-btn>
  11. </div>
  12. <!-- <NuxtLink to="/"> Home page </NuxtLink> -->
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name: 'EmptyLayout',
  18. layout: 'empty',
  19. props: {
  20. error: {
  21. type: Object,
  22. default: null,
  23. },
  24. },
  25. data() {
  26. return {
  27. pageNotFound: '404 Not Found',
  28. otherError: '出现错误',
  29. };
  30. },
  31. head() {
  32. console.log('tempErr',JSON.stringify(this.error))
  33. const title =
  34. this.error.statusCode === 404 ? this.pageNotFound : this.otherError;
  35. return {
  36. title,
  37. };
  38. },
  39. methods: {
  40. // 刷新页面
  41. refreshPage() {
  42. const currentPath = this.$route.path;
  43. const queryParams = this.$route.query;
  44. // 添加一个随机参数以确保刷新
  45. this.$router.replace({
  46. path: currentPath,
  47. query: {
  48. ...queryParams,
  49. _refresh: Date.now()
  50. }
  51. });
  52. }
  53. }
  54. };
  55. </script>
  56. <style scoped>
  57. h1 {
  58. font-size: 20px;
  59. }
  60. </style>