useTimeout


用于在一段时间后更新值

API

const { ready, start, stop } = useTimeout(delay, immediate)

Params

参数名描述类型默认值
delay延时时间number
immediate是否立即启动定时器booleantrue

Result

参数名描述类型
ready定时是否结束boolean
start开启/重启定时器() => void
stop停止定时器() => void

Example

Ready:

Code

<template>
  <p>Ready: {{ ready }}</p>
  <button @click="stop">stop</button>
  <button @click="start">restart</button>
</template>

<script>
import { useTimeout } from 'vue-compositions'
export default {
  setup() {
    const { ready, start, stop } = useTimeout(3000)
    return {
      ready,
      start,
      stop
    }
  }
}
</script>