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":["呀","已"]}]
相关推荐
打不着的大喇叭9 小时前
uniapp的光标跟随和打字机效果
前端·javascript·uni-app
zengzehui10 小时前
uniapp启动图被拉伸问题
uni-app
iOS阿玮12 小时前
AppStore教你一招免备案的骚操作!
uni-app·app·apple
ModyQyW1 天前
用 AI 驱动 wot-design-uni 开发小程序
前端·uni-app
耶啵奶膘2 天前
uniapp+firstUI——上传视频组件fui-upload-video
前端·javascript·uni-app
耶啵奶膘2 天前
uniapp——地图路线绘制map
uni-app
shadouqi2 天前
uniapp实现图片预览,懒加载,下拉刷新等
uni-app
走,带你去玩2 天前
uniapp 微信小程序水印
微信小程序·小程序·uni-app
菌菇汤3 天前
uni-app实现单选,多选也能搜索,勾选,选择,回显
前端·javascript·vue.js·微信小程序·uni-app·app
某公司摸鱼前端3 天前
uniapp socket 封装 (可拿去直接用)
前端·javascript·websocket·uni-app