提交 6238ffb0 编写于 作者: X xiaoyucoding

modify: 优化 current 值的更新

上级 350e668e
<template>
<view class="segmented-control" :class="styleType" :style="wrapStyle">
<view v-for="(item, index) in values" class="segmented-control-item" :class="styleType" :key="index" :style="index === current ? activeStyle : itemStyle"
@click="onClick(index)">
<view v-for="(item, index) in values" class="segmented-control-item" :class="styleType" :key="index" :style="index === currentIndex ? activeStyle : itemStyle"
@click="onClick(index)">
{{item}}
</view>
</view>
......@@ -30,6 +30,18 @@
default: 'button'
}
},
data() {
return {
currentIndex: this.current
}
},
watch: {
current(val) {
if (val !== this.currentIndex) {
this.currentIndex = val;
}
}
},
computed: {
wrapStyle() {
let styleString = '';
......@@ -70,8 +82,8 @@
},
methods: {
onClick(index) {
if (this.current !== index) {
this.current = index;
if (this.currentIndex !== index) {
this.currentIndex = index;
this.$emit('clickItem', index);
}
}
......@@ -98,7 +110,7 @@
.segmented-control.text {
border: 0;
border-radius: 0upx;
border-radius: 0upx;
}
......@@ -120,4 +132,4 @@
.segmented-control-item:first-child {
border-left-width: 0;
}
</style>
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册