mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 11:17:41 +00:00
[improvement] IndexBar: unify index dataset
This commit is contained in:
@@ -40,7 +40,7 @@ export default sfc({
|
||||
|
||||
data() {
|
||||
return {
|
||||
activeAnchorIndex: -1
|
||||
activeAnchorIndex: null
|
||||
};
|
||||
},
|
||||
|
||||
@@ -95,7 +95,7 @@ export default sfc({
|
||||
|
||||
const active = this.getActiveAnchorIndex(scrollTop, rects);
|
||||
|
||||
this.activeAnchorIndex = active;
|
||||
this.activeAnchorIndex = this.indexList[active];
|
||||
this.children.forEach((item, index) => {
|
||||
if (index === active) {
|
||||
item.active = true;
|
||||
@@ -137,11 +137,11 @@ export default sfc({
|
||||
const { clientX, clientY } = event.touches[0];
|
||||
const target = document.elementFromPoint(clientX, clientY);
|
||||
if (target) {
|
||||
const { idx } = target.dataset;
|
||||
const { index } = target.dataset;
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (this.touchActiveIdx !== idx) {
|
||||
this.touchActiveIdx = idx;
|
||||
if (this.touchActiveIndex !== index) {
|
||||
this.touchActiveIndex = index;
|
||||
this.scrollToElement(target);
|
||||
}
|
||||
}
|
||||
@@ -178,11 +178,10 @@ export default sfc({
|
||||
onTouchend={this.onTouchEnd}
|
||||
onTouchcancel={this.onTouchEnd}
|
||||
>
|
||||
{this.indexList.map((index, idx) => (
|
||||
{this.indexList.map(index => (
|
||||
<span
|
||||
class={bem('index')}
|
||||
style={idx === this.activeAnchorIndex ? this.highlightStyle : null}
|
||||
data-idx={idx}
|
||||
style={index === this.activeAnchorIndex ? this.highlightStyle : null}
|
||||
data-index={index}
|
||||
>
|
||||
{index}
|
||||
|
Reference in New Issue
Block a user