uni-app文章列表制作⑧

文章目录

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

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

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

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

    复制代码
    获取选项卡的数量值,根据选项卡数量进行 swiperItem 渲染,index 界面进行 labelList 传递
    react 复制代码
        <ArticleList :labelList="labelLIst" class="list-container"></ArticleList>
    1. ArticleList 内根据 swiper 数量进行 swiperItem 渲染
    react 复制代码
       <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 属性

      react 复制代码
       <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 属性进行跳转切换

react 复制代码
<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 设定
相关推荐
S***H2831 分钟前
Vue语音识别案例
前端·vue.js·语音识别
00后程序员张30 分钟前
iOS 抓不到包怎么办?从 HTTPS 解密、QUIC 排查到 TCP 数据流分析的完整解决方案
android·tcp/ip·ios·小程序·https·uni-app·iphone
啦啦91188638 分钟前
【版本更新】Edge 浏览器 v142.0.3595.94 绿色增强版+官方安装包
前端·edge
蚂蚁集团数据体验技术1 小时前
一个可以补充 Mermaid 的可视化组件库 Infographic
前端·javascript·llm
前端互助会1 小时前
UNI-APP开发APP避坑指南:这些关键事项你必须掌握
uni-app
LQW_home1 小时前
前端展示 接受springboot Flux数据demo
前端·css·css3
q***d1731 小时前
前端增强现实案例
前端·ar
IT_陈寒1 小时前
Vite 3.0 重磅升级:5个你必须掌握的优化技巧和实战应用
前端·人工智能·后端
JarvanMo1 小时前
Flutter 3.38 + Firebase:2025 年开发者必看的新变化
前端
Lethehong1 小时前
简历优化大师:基于React与AI技术的智能简历优化系统开发实践
前端·人工智能·react.js·kimi k2·蓝耘元生代·蓝耘maas