I'm trying to add a JQuery plugin, owl carousel to a list that rendered using Vuejs.
HTML
<h4>1. Vuejs rendered items with OWL Carousel (not working)</h4>
<div id="user" class="owl-carousel">
<div class="item" v-for="user in users">{{ user.name }}</div>
</div>
<h4>2. Pure HTML with OWL Carousel (working)</h4>
<div class="owl-carousel">
<div class="item">Sunny</div>
<div class="item">Michel</div>
<div class="item">Daneil</div>
<div class="item">Sony</div>
</div>
JS
var list = new Vue({
el: '#user',
data: {
users: []
},
methods: {
listUsers: function() {
var users = [
{
id: 1,
name: 'John'
},
{
id: 2,
name: 'Deo'
},
{
id: 3,
name: 'Anjela'
},
{
id: 4,
name: 'Samantha'
}
];
this.$set('users', users);
},
installOWLcarousel: function() {
$('.owl-carousel').owlCarousel();
}
},
ready: function() {
this.listUsers();
this.installOWLcarousel();
}
});
You can find the entire code from: https://jsfiddle.net/v18yjmuq/12/
I seem JQuery is complete it's execution before Vuejs rendered the list. How to avoid that issue? Can I run JQuery after fully rendered the Vuejs for loop items?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…