count: 0
throlledCount: 0
Defaut usageclick the button fast, Look at what happens to second value
A hook that handle the throttle value.
API is consistent with ahooks.
count: 0 throlledCount: 0Defaut usageclick the button fast, Look at what happens to second value复制成功!<template>
<div>
<p>
count: <span>{{ count }}</span>
</p>
<p>
throlledCount: <span>{{ throlledCount }}</span>
</p>
<button @click="addCount">++count</button>
</div>
</template>
<script lang="ts">
import { useThrottle } from 'ahooks-vue';
import { ref } from 'vue';
export default {
setup() {
const count = ref(0);
const throlledCount = useThrottle(count, { wait: 2000 });
function addCount() {
count.value++;
}
return {
count,
throlledCount,
addCount,
};
},
};
</script>
const throttledValue = useThrottle(
value: any,
options?: object
);
Property | Description | Type | Default |
---|---|---|---|
value | value that requires throttle | any | - |
options | Config the throttle behavior. See the Options section below. | Options | {} |
Property | Description | Type | Default |
---|---|---|---|
wait | The number of milliseconds to delay. | number | 1000 |
leading | Specify invoking on the leading edge of the timeout. | boolean | true |
trailing | Specify invoking on the trailing edge of the timeout. | boolean | true |