<script setup lang="ts">
import { reactive, ref, watch } from 'vue';

const props = defineProps<{
  value?: unknown,
  before: (val: unknown) => Promise<void>,
}>()

// const emits = defineEmits(["update:modelValue"])

const loading = ref(false)

const value = ref(props.value)

watch(
  () => value.value,
  (val, oldVal) => {
    loading.value = true
    props["before"](val).then(() => {
      loading.value = false
    })
  }
)


</script>

<template>
  <el-switch v-model="value" :loading="loading"></el-switch>
</template>
