I'm trying to create a generic slideshow component using slots. I'm able to access the elements passed into the slot, and when I log them they appear to be DOM elements, but when they appear on the page they're just [object HTMLQuoteElement].
Here's the component:
export default {
props: {
// Classes to apply to wrapping element.
cssClasses: { default: '' },
// Integer for miliseconds to remain on each slide.
interval: { default: 5000 }
},
data() {
return {
// Internal: Timer for playing through slides.
timer: null,
// Internal: Current slide.
index: 0
}
},
computed: {
currentSlide() {
if (this.$slots.default[this.index].elm) {
console.log('currentSlide', this.$slots.default[this.index].elm) // prints correctly
return this.$slots.default[this.index].elm // renders wrong
}
return ''
},
slots() {
return this.$slots.default
}
},
methods: {
// Internal: Start slideshow.
startSlide() {
if (this.timer) clearInterval(this.timer)
this.timer = setInterval(this.next, this.interval)
},
// Internal: Render next slide. If at end, return to the beginning.
next() {
this.startSlide()
if (this.index === this.slots.length - 1) {
this.index = 0
} else {
this.index += 1
}
}
},
mounted() {
this.startSlide()
}
}
The goal is to be able to pass any html elements into the slot so the slideshow goes through them. At this point I'm just adding nonsense text because stack overflow won't let me post my question because it's mostly code. But really, there isn't much more to say. You can read the code. You know what I'm trying to do. If I'm doing something wrong, let me know. There isn't a point in me wasting both of our time so a robot can count characters to decide one has enough information.