<script lang="ts" setup> import {ref, onMounted, onUnmounted} from "vue"; let timer = <any>ref(null); onMounted(() => { // 设置每隔5秒刷新一次 timer.value = setInterval(() => { // 这里引用你想调用的方法 }, 5000); }); // 在组件卸载之后清除定时器 onUnmounted(() => { clearInterval(timer.value); }); <script>
标签:定时器,setInterval,onMounted,value,timer,ref From: https://www.cnblogs.com/gamepen/p/17705046.html