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":["呀","已"]}]
相关推荐
小徐_23332 天前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
iOS阿玮2 天前
永远不要站在用户的对立面,挑战大众的公知。
uni-app·app·apple
xw52 天前
uni-app中v-if使用”异常”
前端·uni-app
!win !2 天前
uni-app中v-if使用”异常”
前端·uni-app
2501_915918412 天前
iOS 上架全流程指南 iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传 ipa 与审核实战经验分享
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张2 天前
iOS App 混淆与加固对比 源码混淆与ipa文件混淆的区别、iOS代码保护与应用安全场景最佳实践
android·安全·ios·小程序·uni-app·iphone·webview
00后程序员张3 天前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview
海绵宝宝不喜欢侬3 天前
uniapp-微信小程序分享功能-onShareAppMessage
微信小程序·小程序·uni-app
2501_915106323 天前
Xcode 上传 ipa 全流程详解 App Store 上架流程、uni-app 生成 ipa 文件上传与审核指南
android·macos·ios·小程序·uni-app·iphone·xcode
xkxnq3 天前
Uniapp崩溃监控体系构建:内存泄漏三维定位法(堆栈/资源/线程)
uni-app