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 设定
相关推荐
小雨青年3 分钟前
Cursor 项目实战:AI播客策划助手(二)—— 多轮交互打磨播客文案的技术实现与实践
前端·人工智能·状态模式·交互
Nan_Shu_61416 分钟前
学习:JavaScript(5)
开发语言·javascript·学习
533_19 分钟前
[vue3] h函数,阻止事件冒泡
javascript·vue.js·elementui
通往曙光的路上21 分钟前
day22_用户授权 头像上传
javascript·vue.js·ecmascript
小光学长24 分钟前
基于Vue的儿童手工创意店管理系统as8celp7(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
前端·数据库·vue.js
meichaoWen25 分钟前
【Vue】Vue框架的基础知识强化
前端·javascript·vue.js
jingling55529 分钟前
Flutter | 基础环境配置和创建flutter项目
前端·flutter
mapbar_front32 分钟前
如何判断一个领导值不值得追随
前端
西西学代码34 分钟前
Flutter---DragTarget(颜色拖拽选择器)
前端·javascript·flutter
小光学长34 分钟前
基于Vue的地铁综合服务管理系统7949eg04(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
前端·数据库·vue.js