关于 slider 的 无缝滚动

关于 slider 的 无缝滚动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<template>
<div class="swiper-wrapper-pro">
<!-- 缓加载loading组件 -->
<!-- <div class="loading-container" v-if="!dataImg.length">
      <me-loading></me-loading>
    </div> -->
 
<!-- 幻灯片组件 -->
<me-slider
v-bind:direction="direction"
v-bind:interval="interval"
v-bind:loop="loop"
v-bind:pagination="pagination"
 
>
<swiper-slide v-for="(item, index) in dataImg.slider" v-bind:key="index">
<div class="slider-img-container">
<img v-lazy="item" alt="" class="slider-img">
</div>
</swiper-slide>
</me-slider>
 
</div>
</template>
 
<script>
import MeSlider from 'base/slider';
import MeLoading from 'base/loading';
import {swiperSlide} from 'vue-awesome-swiper';
import {swiperOption} from './config';
 
export default {
name:'productSlider',
 
data () {
return {
sliders: [],
direction: swiperOption.direction,      //幻燈片滑動方向
loop: swiperOption.loop,               //無縫滾動
interval: swiperOption.interval,      //輪播開關(0<開啟)及速度
pagination: swiperOption.pagination, //分頁器
};
},
 
// index.vue 已经将图片赋值了, 所以这里不需要再赋值
props:{
dataImg: {
type: [Array, Object],
default:[],
},
},
 
components: {
'me-slider':MeSlider,
'me-loading':MeLoading,
'swiper-slide':swiperSlide,
},
 
created() {
this.con();
},
 
methods: {
con() {
setTimeout(() => {
// console.log('dataImg', this.dataImg);
},3000);
},
},
 
watch: {
dataImg(val) {
console.log('watch-Val',val);
this.sliders = val;
console.log('sliders'this.sliders.slider)
}
}
 
}
 
</script>
<style lang='scss' scoped>
 
.swiper-wrapper-pro {
height: 283px;
}
 
.slider-img {
width: 100%;
height: 100%;
}
 
.loading-container {
padding-top: 100px;
}
</style>

请问老师:

为什么 我已经挂入 loop 了,但 最后一张 没办法 向右滑动,立刻回到第一张?

请老师解惑,谢谢您。

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,首先, 我们来分析为什么传入loop但是无法实现无缝轮播

因为在base/slider组件中, 通过监听父组件传入的dataSlider值来判断是给swiper组件设置loop属性, 你在product.vue中没有传入dataSlider,  所以无法开启无缝轮播

http://img1.sycdn.imooc.com//climg/5d70c8550001132409560350.jpg

建议:给组件绑定dataSlider值

http://img1.sycdn.imooc.com//climg/5d70c8d800016e6f09260397.jpg

这样修改之后,虽然可以实现无缝轮播, 但是由于同学给轮播图片添加了懒加载, 导致最后一张切换到第一张之间显示空白。

建议:可以不使用懒加载技术,在显示整个banner区域之前添加一个判断,判断是否有数据,如果没有数据, 显示loading效果, 如果有数据的时候,直接显示轮播图片就可以了。 这样就不用在每一张加载的时候都显示loading过程了, 

http://img1.sycdn.imooc.com//climg/5d70ca660001e0fe10180636.jpg

另, 需要注意一下, dataImg包括content和slider信息, 可以将slider直接赋值给sliders,方便后续的操作哦

http://img1.sycdn.imooc.com//climg/5d70ca410001018e07510311.jpg

如果帮助到了你, 欢迎采纳!

祝学习愉快~~~~

  • 慕小庄 提问者 #1
    完美解答,謝謝老師!
    2019-09-05 17:09:06
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码