बटन·मुफ़्त
एसिंक बटन (Vue)
Vue 3 बटन जो एक एसिंक काम चलाता है, इंतज़ार के दौरान स्पिनर दिखाता है और काम पूरा होने तक अतिरिक्त टैप अनदेखे करता है। यह done या error भेजता है, ताकि आगे क्या दिखाना है यह आप तय करें। TypeScript, कोई लाइब्रेरी नहीं।
मुफ़्त में इंस्टॉल करें।
अगर आपके Android डिवाइस पर PocketCode इंस्टॉल है, तो यह पेज ऐप में खुलेगा।
प्रीव्यू
AsyncButton.vue · 108 लाइनें
<!--
A button for Vue 3 that runs an async action and blocks double taps while it waits.
While `action` runs it shows a spinner and `pendingLabel`, sets aria-busy and ignores new
clicks. If the promise rejects, the button comes back and emits `error`.
<AsyncButton :action="save" pending-label="Saving…" @error="showError">Save</AsyncButton>
Colours: --button-bg and --button-text (white text on near-black by default).
-->
<script setup lang="ts">
import { ref } from 'vue';
const props = withDefaults(
defineProps<{
action: () => Promise<unknown>;
pendingLabel?: string;
disabled?: boolean;
}>(),
{ pendingLabel: 'Working…', disabled: false },
);
const emit = defineEmits<{ done: []; error: [reason: unknown] }>();
const running = ref(false);
async function run() {
if (running.value || props.disabled) return;
running.value = true;
try {
await props.action();
emit('done');
} catch (reason) {
emit('error', reason);
} finally {
running.value = false;
}
}
</script>
<template>
<button
type="button"
class="async-button"
:disabled="disabled"
:aria-disabled="running || undefined"
:aria-busy="running || undefined"
@click="run"
>
<span v-if="running" class="spinner" aria-hidden="true"></span>
<span>
<template v-if="running">{{ pendingLabel }}</template>
<slot v-else>Continue</slot>
</span>
</button>
</template>
<style scoped>
.async-button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
min-height: 44px;
min-width: 44px;
padding: 0.55rem 1.1rem;
font: 600 1rem system-ui, sans-serif;
color: var(--button-text, #ffffff);
background: var(--button-bg, #1d1f23);
border: 0;
border-radius: 8px;
cursor: pointer;
}
.async-button[aria-busy='true'] {
cursor: progress;
}
.async-button:disabled {
opacity: 0.5;
cursor: not-allowed;यह प्रीव्यू छोटा किया गया है। पूरा कंटेंट इंस्टॉल करने पर मिलेगा।
1.0.0 में बदलाव
पहला संस्करण।