html代码
<div id="slider" class="mui-slider">
<div class="mui-slider-group mui-slider-loop">
<div class="mui-slider-item mui-slider-item-duplicate">
<img :src="beforebannertop" alt="" width="100%" height="148px">
</div>
<div class="mui-slider-item" v-for="item in mallHomeCarousel">
<img :src="item.banner" alt="" width="100%" height="148px"/>
</div>
<div class="mui-slider-item mui-slider-item-duplicate">
<img :src="lastbannertop" alt="" width="100%" height="148px">
</div>
</div>
<div class="mui-slider-indicator">
<div class="mui-indicator mui-active" style="margin:1px 5px 1px 0;"></div>
<div v-for="item in CarouselClass" :class="item._class" style="z-index: 100;"></div>
</div>
</div>
js部分
data: {
mallHomeCarousel:[
],
CarouselClass:[
],
beforebannertop:'./images/advert2.png',
lastbannertop:'./images/homeBackImg.png'
}
function getbannertop(){
var getUrl = my_url + 'api/com/index_banner';
var data = {
type:1
}
postDate(getUrl,data,'POST',function(data){
if(data.code == 200){
var res = data.data;
this_obj.lastbannertop = res[0].logo;
for(var i in res){
this_obj.mallHomeCarousel.push({
banner:res[i].logo,
_thisclass:"mui-slider-item"
})
if(i == res.length-1){
this_obj.beforebannertop = res[i].logo;
for(var k in res){
if(k == 0){
}else{
this_obj.CarouselClass.push({
_class:'mui-indicator'
})
}
}
}
}
}
})
}
function postDate(path,data,type,callback){
$.ajax({
type: type,
url:path,
data:data,
dataType: 'json',
success:function(data){
console.log('成功 : '+path);
callback(data);
},
error:function(xhr, type) {
console.log(typeof(xhr.responseText));
console.log('失败 : '+path);
mui.toast('链接错误');
}
});
}