useLockFn
给函数设置单行道,只有此函数执行完毕才能执行下一个
Demo
sum:0
-------
sum2:0
Usage
html
<template>
<div>
<p>sum:{{ sum }}</p>
<button @click="fun">(异步)点击加 1</button>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { useLockFn } from '@morehook/core'
const sum = ref(0)
const fun = useLockFn(
() =>
new Promise<void>(resolve => {
sum.value++
setTimeout(() => {
resolve()
}, 1000)
})
)
</script>
Type Declarations
typescript
type ArgsAny = any[]
type Fn = (...args: ArgsAny) => Promise<any> | void
/**
* 给函数设置单行道,只有此函数执行完毕才能执行下一个
* @param fn 需要执行的函数
* @returns 返回待执行函数
*/
export declare function useLockFn(fn: Fn): (...args: ArgsAny) => Promise<any>