I am using vue.js with rails and adding owlcarousel for the project with static images works without any problem and is shown as follows:
but when I use it dynamically with vue requesting an API send me the images without respecting the carousel this is the code:
script:
<script>
export default {
data: {
videos_p: []
},
mounted() {
axios.get("xxxxxxxxxxx")
.then(response => {
this.videos_p = response.data
console.log(this.videos_p)
})
}
}
$(document).ready(function() {
var owl = $('.owl-carousel');
owl.owlCarousel({
items: 4,
loop: true,
margin: 10,
autoplay: true,
autoplayTimeout: 900,
autoplayHoverPause: true,
responsiveClass: true,
responsive: {
0: {
items: 1,
nav: true
},
600: {
items: 3,
nav: false
},
1000: {
items: 5,
nav: true,
loop: false,
margin: 20
}
}
});
})
</script>
and this is how it is printed in the html:
<section id="demos">
<div class="row">
<div class="large-12 columns">
<div class="owl-carousel owl-theme">
<div class="item" v-for="video in videos_p">
<img v-bind:src="video.image_url">
</div>
</div>
</div>
</div>
</section>
and the image is displayed as follows:
I have to refresh the page 2 times to make the loaded and accept the styles.
Any ideas that may be causing this error ????