uview indexList 按字母跳转不了

点击字母跳转不到位的问题:在<u-index-list>添加方法@select="clickSelect"

锚点要加id,用对应的字母做为id值,

复制代码
<u-index-anchor :id="key" :index="key"/>
复制代码
<template>
  <view>
    <view class="search">
      <u-search v-model="keywords" @custom="search" @search="search" :margin="'0px 0 0 0'"></u-search>
    </view>
    <view class="wrap ">
      <u-index-list class="container" :offsetTop="190" :scrollTop="scrollTop" @select="clickSelect"
                    :index-list="indexList">
        <view class="personal-listitem" v-for="(key, idx) in indexList" :key="idx" :use-slot="true">
          <view class="personal-listitem" :use-slot="true" data-top="idx">
            <u-index-anchor :id="key" :index="key"/>
            <view class="list-cell" v-for="(item, index) in listByLetter[idx]" :key="index"
                  @click="navTo('')">
              <view class="user-images-new">{{ key }}</view>
              <view class="user-name"><span>{{ item}}</span>
                <span class="user-other">{{ key }}</span>
              </view>
            </view>
          </view>
        </view>
      </u-index-list>
      <u-divider>已经到底了</u-divider>
    </view>
  </view>
</template>

字母点击事件

复制代码
  clickSelect(e) {
      //从当前位置到达目标位置
      console.log(">>>当前节点", e, this.scrollTop)
      try {
        uni
            .createSelectorQuery()
            .select('#' + e)
            .boundingClientRect((data) => {
              console.log(">>data", data)
              //目标位置的节点:类或者id
              uni
                  .createSelectorQuery()
                  .select('.container')
                  .boundingClientRect((res) => {
                    console.log(data, res)
                    console.log(">>res.top", res.top)

                    //最外层盒子的节点:类或者id
                    this.$nextTick(() => {
                      uni.pageScrollTo({
                        scrollTop: data.top - res.top,
                        // selector: '#' + e,
                        duration: 100 //app端这个必须设置成0
                      })
                    })
                  })
                  .exec()
            })
            .exec()
      } catch (e) {

      }
    },

点击跳转:

出现字母乱跳:indexlist传入的数组字母,没跟真实的左侧的列表匹配上。

:index-list="indexList",如下例子,遍历之后右侧应该不是26个字母,是a,b,d,w,x,y这几个。

复制代码
let indexList=[
{"letter":"a","data":["啊","爱","按"]},
{"letter":"b","data":["不"]},
{"letter":"d","data":["懂"]},
{"letter":"w","data":["我"]},
{"letter":"x","data":["县","选"]},
{"letter":"y","data":["呀","已"]}]
相关推荐
2501_9159184110 小时前
掌握 iOS 26 App 运行状况,多工具协作下的监控策略
android·ios·小程序·https·uni-app·iphone·webview
知识分享小能手10 小时前
uni-app 入门学习教程,从入门到精通,uni-app基础扩展 —— 详细知识点与案例(3)
vue.js·学习·ui·微信小程序·小程序·uni-app·编程
2501_9159090613 小时前
iOS 混淆实战,多工具组合完成 IPA 混淆与加固(源码 + 成品 + 运维一体化方案)
android·运维·ios·小程序·uni-app·iphone·webview
赵庆明老师14 小时前
Uniapp微信小程序开发:EF Core 中级联删除
uni-app
Javashop_jjj15 小时前
三勾软件| 用SpringBoot+Element-UI+UniApp+Redis+MySQL打造的点餐连锁系统
spring boot·ui·uni-app
Q_Q5110082851 天前
python+uniapp基于微信小程序的心理咨询信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
HuYi_code1 天前
WeChat 小程序下载文件实现
微信小程序·uni-app
00后程序员张1 天前
HTTPS 包 抓取与分析实战,从抓包到解密、故障定位与真机取证
网络协议·http·ios·小程序·https·uni-app·iphone
2501_915921431 天前
iOS混淆与IPA加固实战手记,如何构建苹果应用防反编译体系
android·macos·ios·小程序·uni-app·cocoa·iphone
Q_Q5110082851 天前
python+uniapp基于微信小程序的学院设备报修系统
spring boot·python·微信小程序·django·flask·uni-app