vue 列表无限滚动列表,循环完自动切换tab

embedded/2024/9/23 4:22:13/

记录一下大屏常用的滚动组件 vue-seamless-scroll  以及滚动完自动切换tab效果。

1.下载vue-seamless-scroll插件

javascript">npm install vue-seamless-scroll --save

2.页面使用

javascript"><vueSeamlessScroll @ScrollEnd="changeScroll" :data="nowlist" :class-option="defaultOption" class="fxsfdw_list"><div v-for="(item, index) in nowlist" :key="index"><div class="ttflex"><div class="items w1">{{ item.name }}</div><div class="items w2">{{ item.age }}</div><div class="items w3">{{ item.class }}</div></div></div>//循环完一次增加间隔<div style="height: 20px;"></div>
</vueSeamlessScroll>
<script>
import vueSeamlessScroll from "vue-seamless-scroll"
export default {components: {vueSeamlessScroll},
}
</script>

3.监听列表滚动完毕执行定时任务

需要用到插件的一个方法 @ScrollEnd 官网没有介绍,这个方法是列表滚动完毕一次就会执行。

javascript">  methods: {jumptype() {clearTimeout(this.timeOut)this.active = this.active + 1console.log(this.active);if (this.active == 3) {this.active = 0this.nowlist = this.userInfo.list1} else if (this.active == 1) {this.nowlist = this.userInfo.list2} else if (this.active == 2) {this.nowlist = this.userInfo.list3}if (this.nowlist.length < 4) {this.timeOut = setTimeout(() => {this.jumptype()}, 3000);}}, //监听列表滚动完毕changeScroll() {if (this.nowlist.length) {this.jumptype()}}},

4.完整测试代码

注意滚动列表最好要定义高度,高度与你设置limitMoveNum 属性相关联否则列表滚动会有间隔!

javascript"><template><div><div class="tit_flex"><div class="tit_item" :class="active == index ? 'activeitem' : ''" v-for="(item, index) in classList" :key="index"@click="changeType(item, index)">{{ item.name }}</div></div><div class="content"><div class="tflex"><div class="items w1">姓名</div><div class="items w2">年龄</div><div class="items w3">班级</div></div><!-- 注意滚动列表最好要定义高度,高度与你设置limitMoveNum 属性相关联否则列表滚动会有间隔  !!!!!--><vueSeamlessScroll @ScrollEnd="changeScroll" :data="nowlist" :class-option="defaultOption" class="fxsfdw_list"><div v-for="(item, index) in nowlist" :key="index"><div class="ttflex"><div class="items w1">{{ item.name }}</div><div class="items w2">{{ item.age }}</div><div class="items w3">{{ item.class }}</div></div></div><div style="height: 20px;"></div></vueSeamlessScroll></div></div>
</template><script>
import vueSeamlessScroll from "vue-seamless-scroll"
export default {components: {vueSeamlessScroll},name: 'TestSa',data() {return {classList: [{id: 1,name: '一班'},{id: 2,name: '二班'},{id: 3,name: '三班'}],active: 0,userInfo: {list1: [{name: '张三',age: 20,class: '一班'},{name: '张三',age: 120,class: '一班'},{name: '李四',age: 9,class: '一班'},{name: '王五',age: 1,class: '一班'},{name: '二狗',age: 22,class: '一班'},{name: '阿萨德',age: 20,class: '一班'}],list2: [{name: '张三',age: 20,class: '二班'},{name: '张三',age: 120,class: '二班'},{name: '李四',age: 9,class: '二班'},{name: '王五',age: 1,class: '二班'},{name: '二狗',age: 22,class: '二班'},{name: '阿萨德',age: 20,class: '二班'}],list3: [{name: '张三',age: 20,class: '三班'},{name: '张三',age: 120,class: '三班'},{name: '李四',age: 9,class: '三班'},{name: '王五',age: 1,class: '三班'},{name: '二狗',age: 22,class: '三班'},{name: '阿萨德',age: 20,class: '三班'}]},nowlist: [],timeOut: null}},computed: {defaultOption() {return {step: 0.4, // 数值越大速度滚动越快hoverStop: true, // 是否开启鼠标悬停stopdirection: 1, // 0向下 1向上 2向左 3向右openWatch: true, // 开启数据实时监控刷新domsingleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动)direction => 0/1                                singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3waitTime: 1000, // 单步运动停止的时间(默认值1000ms)limitMoveNum: 4 // 多少条开始滚动}},},mounted() {this.nowlist = this.userInfo.list1},methods: {changeType(item, index) {console.log(item, index);this.active = indexif (index == 0) {this.nowlist = this.userInfo.list1} else if (index == 1) {this.nowlist = this.userInfo.list2} else {this.nowlist = this.userInfo.list3}},jumptype() {clearTimeout(this.timeOut)this.active = this.active + 1console.log(this.active);if (this.active == 3) {this.active = 0this.nowlist = this.userInfo.list1} else if (this.active == 1) {this.nowlist = this.userInfo.list2} else if (this.active == 2) {this.nowlist = this.userInfo.list3}if (this.nowlist.length < 4) {this.timeOut = setTimeout(() => {this.jumptype()}, 3000);}},changeScroll() {if (this.nowlist.length) {this.jumptype()}}},
}
</script>
<style scoped>
.tit_flex {width: 300px;display: flex;justify-content: space-between;border: 1px solid #eee;height: 38px;align-items: center;
}.tit_item {width: 30%;cursor: pointer;
}.activeitem {color: red;
}.content {width: 300px;border: 1px solid #eee;
}.tflex {display: flex;justify-content: space-between;background: #eee;
}.tflex .items {}.w1 {width: 30%;
}.w2 {width: 30%;
}.w3 {width: 30%;
}.fxsfdw_list {overflow: hidden;height: 200px;
}.ttflex {display: flex;justify-content: space-between;padding: 6px 4px;
}
</style>


http://www.ppmy.cn/embedded/98518.html

相关文章

合并两个有序链表--力扣

题目如下: 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例如下: 示例 1&#xff1a; 输入&#xff1a;l1 [1,2,4], l2 [1,3,4] 输出&#xff1a;[1,1,2,3,4,4]示例 2&#xff1a; 输入&#xff1a;l1 [], l2 …

VSCode配置ssh免密连接远程服务器

我配置了免密设置(Windows利用ssh免密码登录Linux)&#xff0c;git bash已经能够正常连接了&#xff0c;但是vscode还是不行&#xff0c;很奇怪。 VSCode报错信息&#xff1a; [17:55:50.360] SSH Resolver called for "ssh-remote106.52.2.19", attempt 5, (Recon…

VAuditDemo常规漏洞

VAuditDemo常规漏洞 一、留言类功能漏洞 messageDetail.php - 存在数字型SQL注入&#xff0c;反射型XSS SQL注入 sqlwaf修改措施 反射型XSS messageSub.php search.php - 存在反射型xss 二、用户操作类漏洞 1、登录功能 logCheck.php - 空验证码绕过漏洞 2、编辑用户信息类 upd…

人脸识别设计

总体思路 人脸识别使用的算法思路为&#xff1a;首先&#xff0c;定位一张图像中所有的人脸位置&#xff1b;其次&#xff0c;对于同一张脸&#xff0c;当光线改变或者朝向方位改变时&#xff0c;算法还能判断是同一张脸&#xff1b;然后找到每一张脸不同于其他脸的独特之处&a…

学生党运动耳机推荐都有哪些?五大适合学生党使用的运动耳机推荐

在天气比较舒适的时候&#xff0c;不少朋友喜欢骑车出行了&#xff0c;我自己没事也喜欢去公园散步、骑车&#xff0c;外出途中有音乐相伴那是最好不过了。我使用过降噪耳机、骨传导耳机、传统入耳式有线耳机等&#xff0c;各种耳机的使用体验差异相差不大&#xff0c;不过有一…

salesforce如何导出字段名称和api name的对应关系

在 Salesforce 中&#xff0c;如果你想导出某个对象的字段名称及其对应的 API 名称&#xff0c;你可以通过以下几种方法来实现&#xff1a; 方法一&#xff1a;使用 Salesforce Schema Builder 打开 Schema Builder: 进入 Salesforce 后&#xff0c;导航到 Setup&#xff08;设…

微信小程序开发时数据是否是双向数据绑定的

在微信小程序开发中&#xff0c;数据绑定机制允许开发者将应用程序中的数据模型&#xff08;在JavaScript中定义的变量和对象&#xff09;与用户界面&#xff08;UI&#xff09;元素直接关联起来。关于微信小程序是否支持双向数据绑定&#xff0c;可以从以下几个方面进行说明&a…

Spring Mybatis拦截器配合logback打印完整sql语句

在项目开发与维护过程中&#xff0c;常常需要对程序执行的sql语句&#xff0c;进行观察和分析。但是项目通常默认会使用org.apache.ibatis.logging.stdout.StdOutImpl日志配置&#xff0c;该配置是用System.out.println打印的日志&#xff0c;导致只能将执行语句打印到控制台&a…