vue 开发 滑动页面中出现tabs 并且需要分页的

效果

需求

我们这个页面顶部有tabs 栏 而且可以滑动到底部 进行分页

实现这样的页面我们应该怎么做  你应该会想到scroll-view 这个组件吧

下面我们来详情介绍一下这个页面的实现和功能开发

首先展示一下代码

item  循环项

<template><div class="wechat-order-item-container"><div class="box"><div class="header"><div class="cinema-name">金逸影城(安庆星光荟店)</div><div class="status">订单超时</div></div><div class="content"><div class="movie-img"><imagesrc="https://gw.alicdn.com/tfscom/i3/O1CN01s4djbH29FutyK4fzY_!!6000000008039-0-alipicbeacon.jpg_300x300.jpg"style="width: 90px; border-radius: 5px"mode="widthFix"></image></div><div class="movie-data"><div class="name marginTop">我们一起摇太阳</div><div class="time marginTop">2024-04-15 21:30:00</div><div class="hall marginTop color858a99">4号激光厅</div><div class="address marginTop color858a99">宜秀区独秀大道安庆星光荟第四层</div><div class="seat marginTop color858a99">4排六座</div></div><div class="right"><div class="city">安庆市</div><div class="num">共1张</div><div class="price">¥45.00</div></div></div><div class="footer"><div class="timer">创建时间:2024-04-15 17:34</div><div class="btn"><nut-buttonplaintype="default"size="small"style="border: 1px solid #eee">订单详情</nut-button></div></div></div></div>
</template>
<script setup></script>
<style lang="scss">
.wechat-order-item-container {background-color: #fff;padding: 20px 25px;font-size: 26px;border-radius: 15px;.box {.header {color: #858a99;padding-bottom: 20px;display: flex;align-items: center;justify-content: space-between;border-bottom: 1px solid #f7f8f9;.cinema-name {}.status {font-size: 24px;}}.content {padding: 20px 0;border-bottom: 1px solid #f7f8f9;display: flex;.right {flex: 1;margin-left: 20px;display: flex;flex-direction: column;align-items: center;.city {color: #15181d;font-weight: 700;}.num {}.price {color: #028fd4;}}.movie-data {margin-left: 20px;.marginTop {margin-top: 5px;}.color858a99 {color: #858a99;}.name {font-size: 26px;color: #15181d;font-weight: 700;}.time {color: #028fd4;}}}.footer {margin-top: 15px;display: flex;justify-content: space-between;align-items: center;.timer {color: #858a99;font-size: 24px;}}}
}
</style>

这个算是 每一个item的代码 我把他封装成了一个组件

tabs 栏

<template><div class="filter-container"><nut-tabs v-model="selected" title-scroll type="smile" title-gutter="10"><nut-tab-pane v-for="item in tabList" :title="item.name"></nut-tab-pane></nut-tabs></div>
</template>
<script setup>
import { ref, watch, toRefs } from "vue";
const props = defineProps({tabList: Array,
});
const emit = defineEmits(["onChange"]);
const { tabList } = toRefs(props);
const selected = ref(0);//监听当前的tabs选中 变化出发自定一函数 子传父组件数据
watch(selected, (index) => {emit("onChange", tabList.value[index]);
});
</script>
<style lang="less">
.filter-container {.nut-tabs__content {display: none !important;}.nut-tabs__list {background-color: #fff;}.nut-tabs__titles {// background: #ffffff !important;.nut-tabs__titles-item {.nut-tabs__titles-item__smile {display: none;}.nut-tabs__titles-item__text {color: #858a99;font-size: 24px;}.nut-tabs__titles-item__line {background: linear-gradient(to right, #028fd4, #028fd6) !important;}.nut-tabs__titles-item__smile .nut-icon {color: #028fd4 !important;}}.nut-tabs__titles-item.active {.nut-tabs__titles-item__smile {display: block;margin-top: 10px !important;}.nut-tabs__titles-item__text {color: #15181d;}}}
}
</style>

我也把他封装成了一个组件 都是经过二次封装的

这个做法 巧妙的将每一项的item 的上下距离页拉开了

<template><div class="wechat-order-container"><Tabbar></Tabbar><div class="wechat-list" :style="{ marginTop: `${tabbarHeight}` + 'px' }"><Filter :tab-list="tabList" @onChange="handleClickTabs"></Filter><divclass="flex-list":style="{ height: `${listContainerHeight}` + 'px' }"><templatev-if="list.length > 0 && listContainerHeight > 0":style="{ height: `${listContainerHeight}px` }"><scroll-view:scroll-y="true"scrollAnchoring@scrolltolower="onScrollBottom":scroll-top="scrollTop":style="{ height: `${listContainerHeight}` + 'px' }"><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><div class="flex-item"><Item></Item></div><!-- <Loading:page="pageinfo.currentPage":total="totalpage":loadingFlag="loadingFlag":tipFlag="tipFlag"></Loading> --></scroll-view></template><template v-else><nut-empty description="无数据"></nut-empty></template></div></div></div>
</template>
<script>
import { needLogin } from "../../../utils/needLoginHook";
export default {mixins: [needLogin],
};
</script>
<script setup>
import { onMounted, ref, computed } from "vue";
import Taro, { useDidShow } from "@tarojs/taro";
import { storeToRefs } from "pinia";
import Tabbar from "../../../components/wx-tabbar/index.vue";
import Filter from "./filter.vue";
import { useTabbarStore } from "../../../store";
import Item from "./item.vue";
const tabbarStore = useTabbarStore();
const { selected, tabbarHeight } = storeToRefs(tabbarStore);
onMounted(() => {tabbarStore.setSelected(1);
});
useDidShow(() => {getListContainerHeight();
});
const list = ref([1, 2, 3]);
const scrollTop = ref(0);
const listContainerHeight = ref(0);
const tabList = ref([{id: 0,name: "全部",},{id: 1,name: "已创建",},{id: 2,name: "已支付",},{id: 3,name: "已出票",},{id: 4,name: "已退票",},
]);
//计算当前页面的高度
const getListContainerHeight = () => {const query = Taro.createSelectorQuery().select(".flex-list").boundingClientRect();query.selectViewport();query.exec(function (res) {if (res[0]) {listContainerHeight.value = res[0].height;}});
};
//滑动到底部的执行方法
const onScrollBottom = () => {console.log("到底了");
};
const handleClickTabs = () => {};
</script>
<style lang="scss">
.wechat-order-container {height: 100%;.wechat-list {position: fixed;left: 0;right: 0;bottom: 0;top: 0;display: flex;flex-direction: column;.flex-list {flex: 1;.flex-item {padding: 10px 20px;}}}
}
</style>

主页面的代码

详细介绍

scroll-view 是需要 高度的  这个高度 就是外面盒子的高度

高度计算

const getListContainerHeight = () => {const query = Taro.createSelectorQuery().select(".flex-list").boundingClientRect();query.selectViewport();query.exec(function (res) {if (res[0]) {listContainerHeight.value = res[0].height;}});
};

这个外面的盒子需要去计算 我们计算scroll-view 的高度是和父组件的高度一致得

最后一个注意点

.wechat-list 这个盒子 是需要我们将他变为fixed 的定位 相当于操作就是 属于wechat-list 的了 摆脱了 最外面的大盒子的滑动

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/819898.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

dataease部署安装手册

离线安装 1 环境要求 部署服务器要求&#xff1a; 操作系统: Ubuntu 22.04 / CentOS 7 64 位系统CPU/内存: 4核8G磁盘空间: 200G 2 下载离线安装包 请自行下载 DataEase 最新版本的基础安装包&#xff0c;并复制到目标机器的 /tmp 目录下。 安装包下载链接: 开源社区 - FI…

Clustering and Projected Clustering with Adaptive Neighbors 论文阅读

1 Abstract 许多聚类方法基于输入数据的相似性矩阵对数据组进行划分。因此&#xff0c;聚类结果高度依赖于数据相似性学习。由于相似性度量和数据聚类通常是分两步进行的&#xff0c;学习到的数据相似性可能不是数据聚类的最佳选择&#xff0c;从而导致次优结果。在本文中&…

蓝牙耳机哪个品牌的好?五款实力超群品牌分享推荐!

​音乐不仅仅是一种娱乐&#xff0c;它还能激发灵感、放松心情。一款优质的蓝牙耳机能够让音乐体验更加丰富和便捷。在众多的蓝牙耳机中&#xff0c;我特别挑选了几款在音质、设计和功能上都表现出色的产品。无论你是在家中放松、在健身房锻炼&#xff0c;还是在通勤路上&#…

团体程序设计天梯赛 L2-023 图着色问题

L2-023 图着色问题 分数 25 图着色问题是一个著名的NP完全问题。给定无向图G(V,E)&#xff0c;问可否用K种颜色为V中的每一个顶点分配一种颜色&#xff0c;使得不会有两个相邻顶点具有同一种颜色&#xff1f; 但本题并不是要你解决这个着色问题&#xff0c;而是对给定的一种…

鸿蒙 UI预览报错

SyntaxError: Unexpected end of JSON input 删除entry下的.preview文件 重新刷新预览

【主从恢复】利用xtrabackup备份MySQL主库恢复从库

简介 记录一下自己用xtrabackup恢复从库的经过一、备份 1.用到的参数介绍 --backup: 指明为备份 --target-dir: 备份的目录 --defaults-file:指明服务器的配置文件&#xff0c;此参数必须作为innobackupex的第一个参数&#xff0c;否则报错 --login-path: 从登录文件中读取此…

Mybatis-动态标签

动态标签 1.用于处理SQL语句中的空白字符和多余的逗号 -- prefix&#xff1a;指定在SQL语句开头添加的内容。 -- prefixOverrides&#xff1a;指定需要移除的开头部分的内容。 -- suffix&#xff1a;指定在SQL语句结尾添加的内容。 -- suffixOverrides&#xff1a;指定需要移…

从IPv4到IPv6:解密网络通信的新时代

欢迎来到我的博客&#xff0c;代码的世界里&#xff0c;每一行都是一个故事 从IPv4到IPv6&#xff1a;解密网络通信的新时代 前言ipv4介绍ipv6介绍IPv4与IPv6的区别IPv4地址枯竭问题和IPv6的解决方案 ipv6的优势IPv6在新兴技术领域的应用 ipv4向ipv6的过渡挑战解决方案IPv6部署…

电压比较器LM339介绍和仿真

电压比较器LM339介绍和仿真 &#x1f4d1;LM339相关特性 工作电源电压范围宽&#xff0c;单电源、双电源均可工作&#xff0c;单电源&#xff1a; 2&#xff5e;36V&#xff0c;双电源&#xff1a;1&#xff5e;18V&#xff1b;消耗电流小&#xff0c; Icc1.3mA&#xff1b;输…

2023年待业10个月共313天

2023.5.5美团毕业&#xff0c;至2024.3.14入职下一家公司&#xff0c;待业10个月共313天。这313天&#xff0c;大概经历了3个阶段&#xff1a; 第一阶段 从美团毕业后2023.5.6开始。 虽然在此之前已经开始了部分面试&#xff0c;但合适的机会不多&#xff0c;因为才毕业并不…

怎么使用JMeter进行性能测试?

一、简介 JMeter是Apache软件基金会下的一款开源的性能测试工具&#xff0c;完全由Java开发。它专注于对我们应用程序进行负载测试和性能测量&#xff0c;最初设计用于web应用程序&#xff0c;现在已经扩展到其他测试功能&#xff0c;比如&#xff1a;FTP、Database和LDAP等。…

CompletableFuture用法详解

CompletableFuture 1 前言1.1 Fork/Join1.2 Future接口的局限性 2 正文2.1 神奇的CompletableFuture2.2 CompletableFuture API2.3 组合式异步编程2.4 几个小例子 1 前言 1.1 Fork/Join 1.概念 Fork/Join 是 JDK 1.7 加入的新的线程池实现&#xff0c;它体现的是一种分治思想…

【项目实战】记录一次PG数据库迁移至GaussDB测试(下)

上一篇分享了安装、迁移&#xff0c;本篇将继续分享迁移前操作、 DRS迁移数据、迁移后一致性检查、问题总结及解决方法。 目录 四、迁移前操作 4.1 源端(PG) 4.2 目标端(GaussDB库) 五、DRS迁移数据 5.1 创建复制用户 5.2创建迁移任务。 六、迁移后一致性检查 6.1使用…

maven 基础用法 (终端界面和IDEA界面)

目录 maven定义 Maven环境配置 仓库 本地仓库 关于pom.xml 运行方式 关于maven在IDEA创建 maven定义 Maven 是一个项目管理和整合工具。通过对 目录结构和构建生命周期 的标准化&#xff0c; 使开发团队用极少的时间就能够自动完成工程的基础构建配置。 ​ Maven 简化了…

【HarmonyOS 4+NEXT】开发工具安装指南

&#x1f64b;‍ 一日之际在于晨 ⭐本期内容&#xff1a;开发工具安装 &#x1f3c6;系列专栏&#xff1a;鸿蒙HarmonyOS4NEXT&#xff1a;探索未来智能生态新纪元 文章目录 前言准备工作下载开发工具安装开发工具配置开发环境总结 前言 随着科技的不断进步&#xff0c;智能设…

浅析Redis④:字典dict实现

什么是dict&#xff1f; 在 Redis 中&#xff0c;dict 是指哈希表&#xff08;hash table&#xff09;的一种实现&#xff0c;用于存储键值对数据。dict 是 Redis 中非常常用的数据结构之一&#xff0c;用于实现 Redis 的键空间。 在 Redis 源码中&#xff0c;dict 是一个通用…

7-3 jmu-Java-03面向对象基础-05-覆盖(分数 3)

Java每个对象都继承自Object,都有equals、toString等方法。 现在需要定义PersonOverride类并覆盖其toString与equals方法。 1. 新建PersonOverride类 a. 属性&#xff1a;String name、int age、boolean gender&#xff0c;所有的变量必须为私有(private)。 b. 有参构造方法…

IO流-字节缓冲流

简介 缓冲流就是对原始流进行包装&#xff0c;以提高原始数据流读写数据的性能 缓冲流继承体系 缓冲流的作用 构造器API 代码示例 try(// 创建字节输入流和输出流InputStream is new FileInputStream("test.txt");OutputStream os new FileOutputStream("test…

开源项目|使用go语言搭建高效的环信 IM Rest接口(附源码)

项目背景 环信 Server SDK 是对环信 IM REST API 的封装&#xff0c; 可以节省服务器端开发者对接环信 API 的时间&#xff0c;只需要配置自己的 App Key 相关信息即可使用。 环信目前提供java和PHP版本的Server SDK&#xff0c;此项目使用go语言对环信 IM REST API 进行封装…

在比特币中,1 sat 是多少美元?

普通人绝对想不到&#xff0c;比特币能在2024年达到这个价值&#xff0c;早知道的话&#xff0c;我当初就是破釜沉舟也得买一个啊。 而在4月19号&#xff0c;也将迎来比特币再次减半。减半并不是说玩家手中的比特币要被突然减去一半&#xff0c;而是在后续的挖矿过程中&#xf…