Answer the question
In order to leave comments, you need to log in
How to update styles?
The style is simply taken from data and does not change in place with it. What to do to start working?
<div v-bind:style="{background: 'url('+ photos[currentSlide]+ ')'}" id="slider"></div>
var photos = {
0:'i.jpeg',
1:'i2.jpeg',
2:'i3.jpg'
};
var app = new Vue({
el: '#slider',
data: {
currentSlide: 0,
photos: {
0:'i.jpeg',
1:'i2.jpeg',
2:'i3.jpg'
}
},
methods: {
changeSlideNext: function() {
if(currentSlide == 2){
currentSlide = 0;
}
else currentSlide++;
this.el.style.backgroundImage = "url("+photos[currentSlide]+")"
},
changeSlidePrev: function() {
if(currentSlide == 0){
currentSlide = 2;
}
else currentSlide -= 1;
this.el.style.backgroundImage = "url("+photos[currentSlide]+")"
}
}
});
Answer the question
In order to leave comments, you need to log in
if(currentSlide == 2){
this.el.style.backgroundImage = ...
photos: {
<div :style=`background: url(${photos[currentSlide]})` id="slider"></div>
You can try to do something like:
Further in the code:
computed: {
styleObject: function() {
return {
background: `url(${this.photos[this.currentSlide]})`
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question