Commit 5e8be9b390e88ec056c41ecfcbf8cf6b71e4b1f4

Authored by Rijn
1 parent 77d460e8

fixed add bug. added push test

src/components/carousel/carousel.vue
@@ -147,7 +147,8 @@ @@ -147,7 +147,8 @@
147 add (offset) { 147 add (offset) {
148 let index = this.currentIndex; 148 let index = this.currentIndex;
149 index += offset; 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 this.currentIndex = index; 152 this.currentIndex = index;
152 }, 153 },
153 slide () { 154 slide () {
test/routers/carousel.vue
@@ -19,6 +19,9 @@ @@ -19,6 +19,9 @@
19 <i-button @click="currentIndex = 2">2</i-button> 19 <i-button @click="currentIndex = 2">2</i-button>
20 </Button-group> 20 </Button-group>
21 </i-col> 21 </i-col>
  22 + <i-col span="4">
  23 + <i-button @click="push">Push</i-button>
  24 + </i-col>
22 </Row> 25 </Row>
23 <Carousel style="width: 50%; border: solid 1px #000" 26 <Carousel style="width: 50%; border: solid 1px #000"
24 :current-index.sync="currentIndex" 27 :current-index.sync="currentIndex"
@@ -37,6 +40,9 @@ @@ -37,6 +40,9 @@
37 <Icon type="checkmark" style="font-size: 5em"></Icon> 40 <Icon type="checkmark" style="font-size: 5em"></Icon>
38 </Carousel-item> 41 </Carousel-item>
39 <Carousel-item>test3</Carousel-item> 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 </Carousel> 46 </Carousel>
41 </template> 47 </template>
42 <script> 48 <script>
@@ -45,7 +51,13 @@ @@ -45,7 +51,13 @@
45 return { 51 return {
46 currentIndex: 0, 52 currentIndex: 0,
47 autoplay: true, 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 }