Open History to see the last commit
1<script setup lang="ts">
2import { computed, inject, nextTick, ref, watch } from 'vue'
3import { isPendingKey } from '../transition'
4import BaseSpinner from './BaseSpinner.vue'
5β
6const emit = defineEmits<{ click: [] }>()
7β
8const isPending = inject(isPendingKey, ref(false))
9const isStarted = ref(false)
10const isLoading = computed(() => isStarted.value && isPending.value)
11β
12watch(isPending, (pending) => {
13 if (!pending) {
14 isStarted.value = false
15 }
16})
17β
18const handleClick = async () => {
19 isStarted.value = true
20 emit('click')
21 await nextTick()
22 if (!isPending.value) {
23 isStarted.value = false
24 }
25}
26</script>
27β
28<template>
29 <button :disabled="isLoading" @click="handleClick">
30 <slot />
31 <BaseSpinner v-if="isLoading" />
32 </button>
33</template>