我是靠谱客的博主 自信手套,这篇文章主要介绍uniapp点击侧边栏,对应数据滚动定位,现在分享给大家,希望可以做个参考。

使用 <scroll-view>组件。设置scroll-into-view 的值为右侧标题的 id。点击左侧标题时 切换右侧标题 id (scroll-view | uni-app官网

上代码:

<!-- 左侧标题 -->
<scroll-view
    scroll-y="true"
    style="width: 220rpx"
>
    <view class="tags-sort-left">
        <text
            v-for="(ft, index) in leftTitle"
            :key="index"
            @click="changeLeftTitle(index)"
        >
            {{ ft.title }}
        </text>
    </view>
</scroll-view>

<!-- 右侧内容 -->
<scroll-view
    class="tags-sort-right"
    :scroll-into-view="scrollInto" // 子元素id
    scroll-y="true"
    scroll-with-animation="true"
>
    <template
        v-for="(hotTag, index1) in hotTags"
        :key="index1"
    >
        <view
            :id="'item-' + index1" //这里要动态设置id
            class="tags-box"
        >
        ...布局
        </view>
    </template>
</scroll-view>

// 点击左侧标题,
const changeLeftTitle= (index: number) => {
    state.scrollInto = `item-${index}` //改变右侧id,使其滑动
}

最后

以上就是自信手套最近收集整理的关于uniapp点击侧边栏,对应数据滚动定位的全部内容,更多相关uniapp点击侧边栏内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(121)

评论列表共有 0 条评论

立即
投稿
返回
顶部