我的vue组件是这样的:
<template>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-3" v-for="item in items">
<!-- this is images slider -->
</div>
</div>
</template>
<script>
export default {
...
mounted() {
this.getTopLeague([{league_id: this.leagueId}]) // this is ajax if load first
setTimeout( function(){
$('.slick').slick({slidesToShow: 4, infinite: false});
} , 10000 ); // I set 10 seconds for the finished ajax process just started the slider
},
...
methods: {
changeLeague(leagueId) {
this.getTopLeague([{league_id: leagueId}]) // this is ajax if a link clicked
setTimeout( function(){
$('.slick').slick({slidesToShow: 4, infinite: false});
} , 10000 ); //I set 10 seconds for the finished ajax process just started the slider
}
}
}
</script>
如果执行了代码,则会出现如下错误:
未捕获的TypeError:无法读取null的属性“add” 在jQuery.fn.init.a.fn.slick
10秒或ajax过程结束后发生错误
我将滑块设置为在10秒后运行,因为如果ajax进程尚未完成,则会出现错误
我该如何解决这个问题?