欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > uni-app文章列表制作⑧

uni-app文章列表制作⑧

2025/7/7 9:17:17 来源:https://blog.csdn.net/qq_41988669/article/details/143691555  浏览:    关键词:uni-app文章列表制作⑧

文章目录

    • 十二、文章列表制作-容器组件
        • 一、定义 articleList 组件
        • 二、选项卡自动进行位置调整

十二、文章列表制作-容器组件

一、定义 articleList 组件
  1. 使用 swiper 组件实现滚动效果

https://uniapp.dcloud.io/component/swiper

  1. swiperItem 数量动态话,当前的 swiper 数量应该与选项卡的数量相同

    获取选项卡的数量值,根据选项卡数量进行 swiperItem 渲染,index 界面进行 labelList 传递
    
        <ArticleList :labelList="labelLIst" class="list-container"></ArticleList>
    
    1. ArticleList 内根据 swiper 数量进行 swiperItem 渲染
       <swiper class="swiper-container"><swiper-item v-for="(item,index) in labelList" :key="index"><view class="swiper-item uni-bg-red"><list-item></list-item></view></swiper-item></swiper>
    
  2. 选项卡与 swiper 组件联动效果实现

    1. 选项卡点击事件绑定

      发送事件,调整 activeIndex 值,将 activeIdnex 值调整为父组件传递值

      swiper 制定 current 属性,值为 activeIndex

    2. swiper change 事件监听,实现改变 activeIndex 属性

       <swiper class="swiper-container" :current="activeIndex" @change="changCurrentIndex"><swiper-item v-for="(item,index) in labelList" :key="index"><view class="swiper-item uni-bg-red"><list-item></list-item></view></swiper-item></swiper><script>methods:{changeCurrentIndex(e) {const {current}  = e.detail;this.$emit('changeCurrentIndex',current)}}
      </script>
      
二、选项卡自动进行位置调整
  1. scroll-view 组件添加属性 scroll-with-animation 及 scroll-left 属性 https://uniapp.dcloud.io/component/scroll-view

  2. 动态设置 scrollintoview 属性,为每一项添加 ID 属性进行跳转切换

<scroll-view class="tab-scroll" scroll-x="true" :scroll-into-view="currentIndex" :scroll-with-animation="true"><view class="tab-scroll-box"><view :id="`item${index}`" @click="navClickFn(index)" :class="{active:activeIndex === index}" v-for="(item, index) in labelList" :key="index" class="tab-scroll-item">{{ item.name}}</view></view></scroll-view><script>watch:{activeIndex(index){this.currentIndex = `item${index}`}},data() {return {currentIndex:''}}
</script>
  1. 通过 watch 属性监听 currIndex 值改变,进行 currentIndex 设定

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词