Skip to main content

detach

Removes a handler or interceptor that was registered through on or intercept. Used for cleanup, typically on component teardown.

Usage

detach(tag: number | string | symbol): void;
ArgumentTypeDescription
tagnumber | string | symbolTag returned (or supplied) when the handler was registered.

Example

<script setup lang="ts">
import { ref, onUnmounted } from "vue";
import { Calendar } from "@wx/vue-calendar";
import type { CalendarInstanceApi } from "@wx/vue-calendar";

const api = ref<CalendarInstanceApi>();
const tag = Symbol("delete-guard");

function init(a: CalendarInstanceApi) {
api.value = a;
api.value.intercept(
"delete-event",
p => confirm(`Delete event ${p.id}?`),
{ tag }
);
}

onUnmounted(() => api.value?.detach(tag));
</script>

<template>
<Calendar :events="events" :init="init" />
</template>
  • on — register a handler under a tag.
  • intercept — register an interceptor under a tag.
  • init — capture the api so you can call detach later.