细节优化
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
import { debounce } from "@/util";
|
||||
const props = defineProps({
|
||||
width: {
|
||||
type: String,
|
||||
@@ -28,15 +29,23 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const onBtnClick = async () => {
|
||||
const timer = ref(null);
|
||||
|
||||
const onBtnClick = debounce(async () => {
|
||||
if (props.disabled || loading.value) return;
|
||||
loading.value = true;
|
||||
|
||||
let loadingTimer = null;
|
||||
loadingTimer = setTimeout(() => {
|
||||
loading.value = true;
|
||||
}, 300);
|
||||
|
||||
try {
|
||||
await props.onClick();
|
||||
} finally {
|
||||
clearTimeout(loadingTimer);
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user