vue3 每隔2分钟发送一次请求,并更新界面

如下:
const dataInfo = ref()
const timer = ref()

const fetchData = async () => {
  await HnbdSystemUserListStatus().then((e) => {
    if (e.code == 0) {
      dataInfo.value = e.data
      nextTick()
      timer.value = setTimeout(() => {
        fetchData()
      }, 120000)
    }
  })
  console.log('平台运行状态数据', dataInfo.value)
}
fetchData()

onBeforeUnmount(() => {
  clearTimeout(timer.value)
  timer.value = null
})

  

posted @ 2023-01-16 10:15  李嘉图·RicardoMr  阅读(59)  评论(0)    收藏  举报