fixed add bug. added push test

This commit is contained in:
Rijn 2017-01-16 17:51:03 -06:00
parent 77d460e8c4
commit 5e8be9b390
2 changed files with 15 additions and 2 deletions

View file

@ -147,7 +147,8 @@
add (offset) { add (offset) {
let index = this.currentIndex; let index = this.currentIndex;
index += offset; index += offset;
if (index === this.slides.length) index = 0; while (index < 0) index += this.slides.length;
index = index % this.slides.length;
this.currentIndex = index; this.currentIndex = index;
}, },
slide () { slide () {

View file

@ -19,6 +19,9 @@
<i-button @click="currentIndex = 2">2</i-button> <i-button @click="currentIndex = 2">2</i-button>
</Button-group> </Button-group>
</i-col> </i-col>
<i-col span="4">
<i-button @click="push">Push</i-button>
</i-col>
</Row> </Row>
<Carousel style="width: 50%; border: solid 1px #000" <Carousel style="width: 50%; border: solid 1px #000"
:current-index.sync="currentIndex" :current-index.sync="currentIndex"
@ -37,6 +40,9 @@
<Icon type="checkmark" style="font-size: 5em"></Icon> <Icon type="checkmark" style="font-size: 5em"></Icon>
</Carousel-item> </Carousel-item>
<Carousel-item>test3</Carousel-item> <Carousel-item>test3</Carousel-item>
<Carousel-item v-for="item in pushItem" track-by="$index">
<Icon type="checkmark" style="font-size: 5em"></Icon>{{item}}
</Carousel-item>
</Carousel> </Carousel>
</template> </template>
<script> <script>
@ -45,7 +51,13 @@
return { return {
currentIndex: 0, currentIndex: 0,
autoplay: true, autoplay: true,
autoplaySpeed: 2000 autoplaySpeed: 2000,
pushItem: []
}
},
methods: {
push () {
this.pushItem.push('test');
} }
} }
} }