I am having a bit of a problem getting an array length in vue. The array is in the data object as
data() {
return {
slides: [
{
image: require("@/assets/img/carousel/couple.jpg"),
caption:
"A couple wearing masks kiss in a shopping area in downtown Shanghai, China, on February 16, 2020."
},
{
image: require("@/assets/img/carousel/dogs.jpg"),
caption:
"Dogs wearing masks are seen in a shopping area in downtown Shanghai on February 16, 2020."
},
etc... ]
and then in methods
methods: {
playSlides() {
this.imgSource = this.slides[this.currentSlide].image;
this.figCaption = this.slides[this.currentSlide].caption;
let slideInterval = setInterval(nextSlide, 2000);
function nextSlide() {
console.log(`slides.length is: ${this.slides.length}`);
this.currentSlide = (this.currentSlide + 1) % this.slides.length; // % is same as mod operator
console.log(Array.isArray(this.slides));
}
}
}
};
I know its been a long day but this.slides.length is undefined?? and Array.isArray(this.slides) is false. Any body see what is the problem most appreciated...
const nextSlide = () => {...}to bindthis.