diff --git a/resources/js/components/Elements/Slider.vue b/resources/js/components/Elements/Slider.vue index b4dfc92d1..699e078af 100644 --- a/resources/js/components/Elements/Slider.vue +++ b/resources/js/components/Elements/Slider.vue @@ -125,7 +125,7 @@ export default { scroll(event) { this.position = this.vertical ? event.target.scrollTop : event.target.scrollLeft this.showLeft = this.loop || this.position - this.showRight = this.loop || this.container.offsetWidth + this.position < this.container.scrollWidth - 1 + this.showRight = this.loop || this.container?.offsetWidth + this.position < this.container?.scrollWidth - 1 }, scrollend(event) { let scrollPosition = this.vertical ? event.target.scrollTop : event.target.scrollLeft @@ -154,8 +154,8 @@ export default { index = this.loop ? index + this.slides.length : index this.vertical - ? this.slider.scrollTo({ top: this.container.children[index]?.offsetTop, behavior: behavior }) - : this.slider.scrollTo({ left: this.container.children[index]?.offsetLeft, behavior: behavior }) + ? this.slider.scrollTo({ top: this.container?.children[index]?.offsetTop, behavior: behavior }) + : this.slider.scrollTo({ left: this.container?.children[index]?.offsetLeft, behavior: behavior }) }, handleLoop() { requestAnimationFrame(() => { @@ -176,12 +176,12 @@ export default { let slide = this.childSpan == 0 ? 0 : this.currentSlide this.childSpan = this.vertical - ? (this.container.children[0]?.offsetHeight ?? this.container.offsetHeight) - : (this.container.children[0]?.offsetWidth ?? this.container.offsetWidth) + ? (this.container?.children[0]?.offsetHeight ?? this.container?.offsetHeight) + : (this.container?.children[0]?.offsetWidth ?? this.container?.offsetWidth) this.navigate(slide, 'instant') - this.sliderSpan = this.vertical ? this.container.offsetHeight : this.container.offsetWidth + this.sliderSpan = this.vertical ? this.container?.offsetHeight : this.container?.offsetWidth }) }, }, @@ -219,6 +219,9 @@ export default { return (this.slides?.length ?? 1) - (this.loop ? 0 : this.slidesVisible - 1) }, slides() { + if (!this.mounted || !this.container) { + return [] + } return this.container.querySelectorAll(':scope > :not([data-clone=true])') }, sliderStart() {