【问题标题】:Refreshing url by vue.js通过 vue.js 刷新 url
【发布时间】:2022-12-19 21:06:59
【问题描述】:

我通过 window.location.reload 和 setTimeout 刷新我的页面。它工作正常,但是当我更改 url 时,重新加载函数最后一次在另一页中勾选。 使用 laravel、惯性、vue.js

那是我的代码。知道如何解决这个问题吗?

<script setup>

import { Inertia } from "@inertiajs/inertia";
import { useForm } from '@inertiajs/inertia-vue3'


</script>

<template>

...content

</template>


<script>


    methods: {
        reloadPage() {
            window.location.reload();
        },
        reload() {
            setTimeout(this.reloadPage, 10000);
        }
    },
    mounted() {
        this.reload();
    },
    Unmount(){
        clearTimeout(this.reload());
    }

};


</script>

抱歉我的英语不好 :) 谢谢

【问题讨论】:

  • 我不明白。问题是什么?另外,重新加载页面的目的是什么?只是为了重新加载它?还是您要重新加载它以解决代码中的某些异常行为?

标签: laravel vue.js refresh reload inertiajs


【解决方案1】:

最近开始使用 vue.js,所以请耐心等待。我认为您需要将 timeoutId 传递给 clearTimeout。由于您还没有这样做,即使在卸载组件后,setTimeout() 仍在运行。

这应该适合你!

export default {
  data: () => ({
    timeoutId: null,
  }),
  methods: {
    reloadPage() {
      window.location.reload();
    },
    reload() {
      this.timeoutId = setTimeout(this.reloadPage, 10000);
    },
  },
  mounted() {
    this.reload();
  },
  Unmount() {
    clearTimeout(this.timeoutId);
  },
};

【讨论】:

    猜你喜欢
    • 2013-03-19
    • 1970-01-01
    • 2017-11-06
    • 2017-04-08
    • 2010-10-29
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多