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 | <template> | 1 | <template> |
| 2 | <div> | 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 | <Carousel-item> | 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 | </Carousel-item> | 8 | </Carousel-item> |
| 7 | <Carousel-item> | 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 | </Carousel-item> | 13 | </Carousel-item> |
| 10 | <Carousel-item> | 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 | </Carousel-item> | 18 | </Carousel-item> |
| 16 | </Carousel> | 19 | </Carousel> |
| 17 | - {{ v1 }} | ||
| 18 | - <div @click="v1 = 0">change v1</div> | 20 | + <Button @click="v1 = 2">change</Button> |
| 19 | </div> | 21 | </div> |
| 20 | </template> | 22 | </template> |
| 21 | <script> | 23 | <script> |
| @@ -23,25 +25,20 @@ | @@ -23,25 +25,20 @@ | ||
| 23 | data () { | 25 | data () { |
| 24 | return { | 26 | return { |
| 25 | v1: 0 | 27 | v1: 0 |
| 26 | - }; | 28 | + } |
| 27 | }, | 29 | }, |
| 28 | methods: { | 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 | </script> | 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 | \ No newline at end of file | 43 | \ No newline at end of file |
| 44 | +</style> | ||
| 45 | + |
src/components/carousel/carousel.vue
| @@ -243,8 +243,8 @@ | @@ -243,8 +243,8 @@ | ||
| 243 | this.updateTrackPos(this.hideTrackPos); | 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 | while (index < 0) index += slidesLen; | 248 | while (index < 0) index += slidesLen; |
| 249 | if (((offset > 0 && index === slidesLen) || (offset < 0 && index === slidesLen - 1)) && this.loop) { | 249 | if (((offset > 0 && index === slidesLen) || (offset < 0 && index === slidesLen - 1)) && this.loop) { |
| 250 | // 极限值(左滑:当前索引为总图片张数, 右滑:当前索引为总图片张数 - 1)切换轨道 | 250 | // 极限值(左滑:当前索引为总图片张数, 右滑:当前索引为总图片张数 - 1)切换轨道 |
| @@ -255,7 +255,9 @@ | @@ -255,7 +255,9 @@ | ||
| 255 | if (!this.loop) index = index % this.slides.length; | 255 | if (!this.loop) index = index % this.slides.length; |
| 256 | this.updateTrackIndex(index); | 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 | arrowEvent (offset) { | 262 | arrowEvent (offset) { |
| 261 | this.setAutoplay(); | 263 | this.setAutoplay(); |
| @@ -294,9 +296,6 @@ | @@ -294,9 +296,6 @@ | ||
| 294 | autoplaySpeed () { | 296 | autoplaySpeed () { |
| 295 | this.setAutoplay(); | 297 | this.setAutoplay(); |
| 296 | }, | 298 | }, |
| 297 | - currentIndex (val, oldVal) { | ||
| 298 | - this.$emit('on-change', oldVal, val); | ||
| 299 | - }, | ||
| 300 | trackIndex () { | 299 | trackIndex () { |
| 301 | this.updateOffset(); | 300 | this.updateOffset(); |
| 302 | }, | 301 | }, |