[improvement] IndexBar: unify index dataset

This commit is contained in:
陈嘉涵
2019-05-30 19:12:41 +08:00
parent 0678c7d30b
commit a412c605d1
4 changed files with 13 additions and 10 deletions

View File

@@ -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}