current="current">
<swiper-item>
<view class="swiper-item">111</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">222</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">333</view>
</swiper-item>
</swiper>
<view>当前索引:{{current}}</view>
<button type="default" @click="changeValue(true)">+</button>
<button type="default" @click="changeValue(false)">-</button>
</view>
</template>
<script>
export default {
data() {
return {
current: 0
}
},
methods: {
changeValue(val) {
let oldValue = this.current;
let newValue = 0;
if (val) {
newValue = oldValue + 1 > 2 ? 0 : oldValue + 1;
} else {
newValue = oldValue - 1 < 0 ? 2 : oldValue - 1;
}
this.current = newValue;
}
}
}
</script>
1 个回复
惊悚的毛毛虫 (作者)
示例代码