Not sure if my solution to the buttons works for the previous and next image yet because I am not able to test them because none of the pictures are found. I have them all in the same folder and they are not misspelled. I am not sure why they cannot be found. Thank you all for helping.
The error: "GET /images[currentImage]" Error (404): "Not found"
index.html:
<!DOCTYPE html>
<html>
<head>
<title>Slideshow</title>
</head>
<body>
<div id="app">
<button @click="previousImage">Previous image</button>
<button v-on:click="nextImage">Next image</button><br><br>
<img :src="images[currentImage]" :width="imageWidth">
</div>
</body>
<script src="vue.js"></script>
<script src="app.js"></script>
</html>
app.js:
const customButton = {
template: "<button>Custom button</button>"
};
new Vue({
el: '#app',
data: {
currentImage: 0,
images: ["meme1.PNG", "meme2.PNG", "meme3.JPG", "meme4.PNG"],
imageWidth: 640
},
components: {
customButton
},
methods: {
nextImage() {
if (currentImage == 0) {
currentImage++;
this.currentImage = (this.currentImage + 1) % this.images.length;
}
if (currentImage == 1) {
currentImage++;
this.currentImage = (this.currentImage + 1) % this.images.length;
}
if (currentImage == 2) {
currentImage++;
this.currentImage = (this.currentImage + 1) % this.images.length;
}
if (currentImage == 3) {
this.currentImage = (this.currentImage + 1) % this.images.length;
}
},
previousImage() {
if (currentImage == 0) {
this.currentImage = (this.currentImage - 1) % this.images.length;
}
if (currentImage == 1) {
currentImage--;
this.currentImage = (this.currentImage - 1) % this.images.length;
}
if (currentImage == 2) {
currentImage--;
this.currentImage = (this.currentImage - 1) % this.images.length;
}
if (currentImage == 3) {
currentImage--;
this.currentImage = (this.currentImage - 1) % this.images.length;
}
}
});