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":["呀","已"]}]
相关推荐
艾小逗1 小时前
uniapp快速入门教程,内容来源于官方文档,仅仅记录快速入门需要了解到的知识点
小程序·uni-app·app·es6
鸭子嘎鹅子呱15 小时前
uniapp使用高德地图设置marker标记点,后续根据接口数据改变某个marker标记点,动态更新
uni-app·map·高德地图
计算机源码社20 小时前
分享一个基于微信小程序的居家养老服务小程序 养老服务预约安卓app uniapp(源码、调试、LW、开题、PPT)
android·微信小程序·uni-app·毕业设计项目·毕业设计源码·计算机课程设计·计算机毕业设计开题
Angus-zoe1 天前
uniapp+vue+微信小程序实现侧边导航
vue.js·微信小程序·uni-app
Pluto & Ethereal1 天前
uni-app尺寸单位、flex布局于背景图片
uni-app
天空下sky1 天前
uniapp+若依 开发租房小程序源码分享
uni-app
帅过二硕ฅ1 天前
uniapp点击跳转到对应位置
前端·javascript·uni-app
佩淇呢2 天前
uniapp vue3 梯形选项卡组件
前端·vue.js·uni-app
[廾匸]2 天前
uni-app获取设备唯一值、静态IP以及公网IP的方法
uni-app·ip·imei·唯一值
luckycoke2 天前
小程序的右侧抽屉开关动画手写效果
前端·javascript·微信小程序·uni-app