Commit 5e8be9b390e88ec056c41ecfcbf8cf6b71e4b1f4
1 parent
77d460e8
fixed add bug. added push test
Showing
2 changed files
with
15 additions
and
2 deletions
Show diff stats
src/components/carousel/carousel.vue
| ... | ... | @@ -147,7 +147,8 @@ |
| 147 | 147 | add (offset) { |
| 148 | 148 | let index = this.currentIndex; |
| 149 | 149 | index += offset; |
| 150 | - if (index === this.slides.length) index = 0; | |
| 150 | + while (index < 0) index += this.slides.length; | |
| 151 | + index = index % this.slides.length; | |
| 151 | 152 | this.currentIndex = index; |
| 152 | 153 | }, |
| 153 | 154 | slide () { | ... | ... |
test/routers/carousel.vue
| ... | ... | @@ -19,6 +19,9 @@ |
| 19 | 19 | <i-button @click="currentIndex = 2">2</i-button> |
| 20 | 20 | </Button-group> |
| 21 | 21 | </i-col> |
| 22 | + <i-col span="4"> | |
| 23 | + <i-button @click="push">Push</i-button> | |
| 24 | + </i-col> | |
| 22 | 25 | </Row> |
| 23 | 26 | <Carousel style="width: 50%; border: solid 1px #000" |
| 24 | 27 | :current-index.sync="currentIndex" |
| ... | ... | @@ -37,6 +40,9 @@ |
| 37 | 40 | <Icon type="checkmark" style="font-size: 5em"></Icon> |
| 38 | 41 | </Carousel-item> |
| 39 | 42 | <Carousel-item>test3</Carousel-item> |
| 43 | + <Carousel-item v-for="item in pushItem" track-by="$index"> | |
| 44 | + <Icon type="checkmark" style="font-size: 5em"></Icon>{{item}} | |
| 45 | + </Carousel-item> | |
| 40 | 46 | </Carousel> |
| 41 | 47 | </template> |
| 42 | 48 | <script> |
| ... | ... | @@ -45,7 +51,13 @@ |
| 45 | 51 | return { |
| 46 | 52 | currentIndex: 0, |
| 47 | 53 | autoplay: true, |
| 48 | - autoplaySpeed: 2000 | |
| 54 | + autoplaySpeed: 2000, | |
| 55 | + pushItem: [] | |
| 56 | + } | |
| 57 | + }, | |
| 58 | + methods: { | |
| 59 | + push () { | |
| 60 | + this.pushItem.push('test'); | |
| 49 | 61 | } |
| 50 | 62 | } |
| 51 | 63 | } | ... | ... |