refactor: 메모리 누수 정리 및 타이머 관리 개선, 이벤트 리스너 제거 함수 추가
This commit is contained in:
@@ -26,6 +26,7 @@ const { addArrowClickListeners } = useSplideArrow()
|
||||
|
||||
let mainInst: SplideType | null = null
|
||||
let thumbsInst: SplideType | null = null
|
||||
let removeArrowListeners: (() => void) | null = null
|
||||
|
||||
defineExpose({
|
||||
mainInst: computed(() => mainInst),
|
||||
@@ -111,7 +112,7 @@ onMounted(() => {
|
||||
mainInst.sync(thumbsInst)
|
||||
// 썸네일 슬라이드의 화살표 버튼에 이벤트 리스너 추가
|
||||
nextTick(() => {
|
||||
addArrowClickListeners(thumbsInst, (direction, targetIndex) => {
|
||||
removeArrowListeners = addArrowClickListeners(thumbsInst, (direction, targetIndex) => {
|
||||
emit('arrowClick', direction, targetIndex)
|
||||
})
|
||||
})
|
||||
@@ -119,8 +120,17 @@ onMounted(() => {
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// 이벤트 리스너 제거
|
||||
if (removeArrowListeners) {
|
||||
removeArrowListeners()
|
||||
removeArrowListeners = null
|
||||
}
|
||||
|
||||
// Splide 인스턴스 정리
|
||||
mainInst?.destroy?.()
|
||||
thumbsInst?.destroy?.()
|
||||
mainInst = null
|
||||
thumbsInst = null
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user