vue#onDeactivated TypeScript Examples
The following examples show how to use
vue#onDeactivated.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: use-event-listener.ts From fect with MIT License | 6 votes |
useEventListener = (
event: EventTypes,
listener: EventListenerOrEventListenerObject,
options: Options = {}
) => {
const { target = window, ...rest } = options
const remove = (el: Options['target']) => {
const _el = unref(el)
_el && _el.removeEventListener(event, listener, rest)
}
const add = (el: Options['target']) => {
const _el = unref(el)
_el && _el.addEventListener(event, listener, rest)
}
watch(
() => unref(target),
(el, prevEl) => {
remove(prevEl)
add(el)
}
)
onMounted(() => add(target))
onDeactivated(() => remove(target))
onBeforeUnmount(() => remove(target))
}
Example #2
Source File: use-title.ts From fect with MIT License | 6 votes |
useTitle = (initialTitle = '') => {
const [title, setTitle] = useState<string>(initialTitle)
const titleChange = (title = '') => setTitle(title)
const setDocumentTitle = () => (document.title = title.value)
const resetDocumentTitle = () => (document.title = '')
onMounted(setDocumentTitle)
watch(title, setDocumentTitle)
onBeforeUnmount(resetDocumentTitle)
onDeactivated(resetDocumentTitle)
return {
titleChange,
title
}
}