refactor: 빌드 오류 수정
This commit is contained in:
@@ -631,42 +631,43 @@
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
// 이벤트 위임 핸들러
|
||||
const onDelegatedClick = (e: MouseEvent) => {
|
||||
const target = e.target as HTMLElement | null
|
||||
const el =
|
||||
(target?.closest?.('[data-action]') as HTMLElement | null) ?? null
|
||||
handleCustomAction(el)
|
||||
}
|
||||
|
||||
// onMounted에서 초기화 코드 실행 (CSR에서만)
|
||||
onMounted(() => {
|
||||
if (!import.meta.client) return
|
||||
if (import.meta.client) {
|
||||
onMounted(() => {
|
||||
const container = customContainerRef.value
|
||||
if (!container) return
|
||||
|
||||
const container = customContainerRef.value
|
||||
if (!container) return
|
||||
// fnCustomAction, fnCustomLog 전역 등록
|
||||
window.fnCustomAction = handleCustomAction
|
||||
window.fnCustomLog = handleCustomLog
|
||||
|
||||
// onclick="fnCustomAction(this)", fnCustomLog(this) 지원 (CSR에서만)
|
||||
;window.fnCustomAction = handleCustomAction
|
||||
;window.fnCustomLog = handleCustomLog
|
||||
|
||||
// onclick을 못 쓰는 케이스 대비: 이벤트 위임도 같이 지원
|
||||
const onDelegatedClick = (e: MouseEvent) => {
|
||||
const target = e.target as HTMLElement | null
|
||||
const el =
|
||||
(target?.closest?.('[data-action], [data-log]') as HTMLElement | null) ??
|
||||
null
|
||||
handleCustomAction(el)
|
||||
}
|
||||
|
||||
container.addEventListener('click', onDelegatedClick)
|
||||
onBeforeUnmount(() => {
|
||||
container.removeEventListener('click', onDelegatedClick)
|
||||
// 이벤트 위임 등록
|
||||
container.addEventListener('click', onDelegatedClick)
|
||||
})
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (!import.meta.client) return
|
||||
const w = window as any
|
||||
if (w.fnCustomAction === handleCustomAction) {
|
||||
delete w.fnCustomAction
|
||||
}
|
||||
if (w.fnCustomLog === handleCustomLog) {
|
||||
delete w.fnCustomLog
|
||||
}
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
const container = customContainerRef.value
|
||||
if (container) {
|
||||
container.removeEventListener('click', onDelegatedClick)
|
||||
}
|
||||
|
||||
const w = window as any
|
||||
if (w.fnCustomAction === handleCustomAction) {
|
||||
delete w.fnCustomAction
|
||||
}
|
||||
if (w.fnCustomLog === handleCustomLog) {
|
||||
delete w.fnCustomLog
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user