Commit 2073853e87f9d5d8d39f204bc9293da1a8782b07
1 parent
ab3ff750
fixed #3038
Showing
2 changed files
with
26 additions
and
30 deletions
Show diff stats
examples/routers/carousel.vue
1 | 1 | <template> |
2 | 2 | <div> |
3 | - <Carousel v-model="v1" dots="inside" trigger="hover" autoplay loop radius-dot easing="fade"> | |
3 | + <Carousel v-model="v1" dots="outside" @on-change="hc" :autoplay="false"> | |
4 | 4 | <Carousel-item> |
5 | - <div class="demo-carousel">1</div> | |
5 | + <div class="demo-case-img"> | |
6 | + <img src="https://file.iviewui.com/dist/84b3cded4163febf9dae090e76129322.png"> | |
7 | + </div> | |
6 | 8 | </Carousel-item> |
7 | 9 | <Carousel-item> |
8 | - <div class="demo-carousel">2</div> | |
10 | + <div class="demo-case-img"> | |
11 | + <img src="https://file.iviewui.com/dist/84b3cded4163febf9dae090e76129322.png"> | |
12 | + </div> | |
9 | 13 | </Carousel-item> |
10 | 14 | <Carousel-item> |
11 | - <div class="demo-carousel">3</div> | |
12 | - </Carousel-item> | |
13 | - <Carousel-item> | |
14 | - <div class="demo-carousel">4</div> | |
15 | + <div class="demo-case-img"> | |
16 | + <img src="https://file.iviewui.com/dist/84b3cded4163febf9dae090e76129322.png"> | |
17 | + </div> | |
15 | 18 | </Carousel-item> |
16 | 19 | </Carousel> |
17 | - {{ v1 }} | |
18 | - <div @click="v1 = 0">change v1</div> | |
20 | + <Button @click="v1 = 2">change</Button> | |
19 | 21 | </div> |
20 | 22 | </template> |
21 | 23 | <script> |
... | ... | @@ -23,25 +25,20 @@ |
23 | 25 | data () { |
24 | 26 | return { |
25 | 27 | v1: 0 |
26 | - }; | |
28 | + } | |
27 | 29 | }, |
28 | 30 | methods: { |
29 | - push () { | |
30 | - this.pushItem.push('test'); | |
31 | - }, | |
32 | - slideChange (from, to) { | |
33 | - this.log.push(`From ${from} To ${to}`); | |
31 | + hc (...args) { | |
32 | + console.log(args); | |
34 | 33 | } |
35 | 34 | } |
36 | 35 | } |
37 | 36 | </script> |
38 | -<style> | |
39 | - .demo-carousel{ | |
40 | - height: 200px; | |
41 | - line-height: 200px; | |
42 | - text-align: center; | |
43 | - color: #fff; | |
44 | - font-size: 20px; | |
45 | - background: #506b9e; | |
37 | +<style lang="less"> | |
38 | + .demo-case-img { | |
39 | + img{ | |
40 | + width: 500px; | |
41 | + } | |
46 | 42 | } |
47 | -</style> | |
48 | 43 | \ No newline at end of file |
44 | +</style> | |
45 | + | ... | ... |
src/components/carousel/carousel.vue
... | ... | @@ -243,8 +243,8 @@ |
243 | 243 | this.updateTrackPos(this.hideTrackPos); |
244 | 244 | } |
245 | 245 | // 获取当前展示图片的索引值 |
246 | - let index = this.showCopyTrack ? this.copyTrackIndex : this.trackIndex; | |
247 | - index += offset; | |
246 | + const oldIndex = this.showCopyTrack ? this.copyTrackIndex : this.trackIndex; | |
247 | + let index = oldIndex + offset; | |
248 | 248 | while (index < 0) index += slidesLen; |
249 | 249 | if (((offset > 0 && index === slidesLen) || (offset < 0 && index === slidesLen - 1)) && this.loop) { |
250 | 250 | // 极限值(左滑:当前索引为总图片张数, 右滑:当前索引为总图片张数 - 1)切换轨道 |
... | ... | @@ -255,7 +255,9 @@ |
255 | 255 | if (!this.loop) index = index % this.slides.length; |
256 | 256 | this.updateTrackIndex(index); |
257 | 257 | } |
258 | - this.$emit('input', index === this.slides.length ? 0 : index); | |
258 | + this.currentIndex = index === this.slides.length ? 0 : index; | |
259 | + this.$emit('on-change', oldIndex, this.currentIndex); | |
260 | + this.$emit('input', this.currentIndex); | |
259 | 261 | }, |
260 | 262 | arrowEvent (offset) { |
261 | 263 | this.setAutoplay(); |
... | ... | @@ -294,9 +296,6 @@ |
294 | 296 | autoplaySpeed () { |
295 | 297 | this.setAutoplay(); |
296 | 298 | }, |
297 | - currentIndex (val, oldVal) { | |
298 | - this.$emit('on-change', oldVal, val); | |
299 | - }, | |
300 | 299 | trackIndex () { |
301 | 300 | this.updateOffset(); |
302 | 301 | }, | ... | ... |