Skip to content

useSetInterval

定时器

基础用法

<template>
  <g-button type="primary" @click="handle" :loading="loading">每隔1s执行</g-button>
  <g-button type="danger" @click="clear">销毁</g-button>
  
</template>

<script setup lang="ts">
import { ElMessage } from 'element-plus';
import { GButton, useSetInterval } from 'gao-components-plus'
import { ref } from 'vue';
const loading = ref(false)
const clear = ref(() => {})
function handle() {
  loading.value = true
  const { clear:clean } = useSetInterval(() => {
    ElMessage.success('执行')
  }, 1000)
  clear.value = () => {
    clean()
    loading.value = false
  }
}
</script>

<style lang="scss" scoped>

</style>

参数

名称描述类型默认值
callback回调函数Function-
dalay延迟时间number-

返回参数

名称描述类型默认值
clear关闭定时器Function-

Released under the MIT License.