小程序 切换tab 定位到对应模块

 

    
        
        
        
    
        clickTab(index) {
            console.log("index", index);
            if (!this.tabDomArr || this.tabDomArr.length == 0) {
                this.$u.getRect(`.MarketDetail >>> .anchorClass`, true).then(res => {
                    if (res && res.length > 0) {
                        this.tabDomArr = res;
                        this.toWrap(index);
                    }
                });
            } else {
                this.toWrap(index);
            }
        },
        toWrap(index) {
            let domTop = this.tabDomArr[index].top ? this.tabDomArr[index].top : 0;
            let scrollTop = domTop - this.customBarHeight;
            scrollTop = scrollTop > 0 ? scrollTop : 0;
            uni.pageScrollTo({
                scrollTop: scrollTop,
                duration: 300
            });
        },

你可能感兴趣的:(前端,javascript)