🤓
blog-article
  • Introduction
  • 面试题
    • 1. 输入url发生了什么
  • Personal Works
    • 1. 简单的Web图床
  • CSS动画笔记
    • 1.transition 属性
    • 2.transition 实例
  • css 笔记
    • 1. box-shadow 阴影
    • 2. columns 设置列宽和列数
    • 3. 伪元素after与before
  • html 笔记
    • 1. 不常用的h5标签杂记
  • webpack4
    • 1. 文档学习记录
    • 2. 加载CSS
    • 3. 加载less
    • 4. 加载sass
    • 5. 根据浏览器自动添加css前缀
    • 6. 图片文件处理
    • 7. 字体文件处理
    • 8. 引入jQuery
    • 9. 打包HTML文件
    • 10. 分离css插件
    • 11. babel简单使用
    • 12. 清理旧打包文件插件
    • 13. 拷贝静态资源
  • javascript
    • 1. js获取某年某月的天数
  • npm
    • 2. JSON.stringify()完整用法
    • 1. 入门篇
    • 2. 进阶篇
  • Node.js
    • 1. 使用koa-body中间件后ctx.request.body内容为空
    • 2. uni-app使用Node+Koa2接收上传的文件
  • SQL
    • 1. 查询
    • 2. 插入
    • 3. 修改
    • 4. 删除
    • 5. 期末复习
  • Git
    • 1. git add命令后出现another git process...问题
    • 2. 将文件从暂存区移除
  • vue-cli
    • 1. vue-cli(脚手架)引入vue.config.js文件后热更新失效,每次保存都会刷新页面
  • uni-app
    • 1. uni-app中不使用scroll-view组件,监听页面滑直底部事件
  • 设计模式
    • 创建型模式
    • 单例模式
    • 工厂模式
    • 抽象工厂模式
  • Spring boot
    • 1. 使用自定义参数注解获取 token 中User数据
  • IDEA
    • 1. 设置maven项目的默认配置
  • Linux
    • 1.常用命令
    • 2.常用基础命令2
    • 3.linux目录介绍
    • 4. vi编辑器使用
    • 5.用户管理
    • 6. 文件属性与权限操作
    • 7. 文件归档与解压缩
    • 8. gcc的基本用法
    • 9. gdb调试器的基本用法
    • 10. Makefile基本用法
  • shell
    • shell与crontab定时器的结合
    • 1. shell 变量与常见符号
    • 2. shell中的四则运算符
    • 3. 条件判断
    • 4. 输入输出
    • 5. 输出彩色的内容
    • 6. 流程控制
    • 7. 函数
  • Docker
  • 嵌入式系统给结构及原理
  • 学校课程笔记
    • 1. java EE 复习
    • 2. 马原复习论述题
    • 3. 嵌入式软件技术复习
    • 4. 嵌入式操作系统复习
    • 5. 马原选择题
    • 6. 马原辨析题
    • 7. 马原材料题
    • 8. 计网学习笔记
    • 9. 计网复习
      • 1. 第一章
Powered by GitBook
On this page
  • 最终达到的目标效果
  • 将要用到
  • 标签布局
  • js部分
  • 完整demo代码

Was this helpful?

  1. uni-app

1. uni-app中不使用scroll-view组件,监听页面滑直底部事件

Previousuni-appNext设计模式

Last updated 5 years ago

Was this helpful?

最终达到的目标效果

text-chart-201912517381

将要用到

标签布局

<template>
    <view class="content">
        <!--目标节点-->
        <view class="text-area" id="listArea">
            <view class="square" v-for="(v,i) in info" :key='i'>{{v}}</view>
        </view>
    </view>
</template>

js部分

export default {
        data() {
            return {
                screenHeight: 0, //屏幕高度
                info: [],//展示的列表数据
                isLoading: false, //防止频繁触发
                bottomDistinct:200//距离底部多少像素时触发
            }
        },
        onLoad() {
            //页面加载时取得屏幕高度
            this.screenHeight = uni.getSystemInfoSync().screenHeight;

            //测试数据(初始化)
            this.info=new Array(5).fill(0).map((v,i)=>i+1);
        },
        methods: {
            /**
             *  页面滑动事件
             */
            onPageScroll: function(e) {
                const {
                    scrollTop//滚动条距离页面顶部的像素
                } = e;

                //防止重复触发
                if(this.isLoading){
                    return;
                }
                //获取SelectorQuery 对象实例
                const query = uni.createSelectorQuery().in(this);

                //为listArea节点绑定查询请求
                query.select('#listArea').boundingClientRect(data => {
                    let {
                        height//listArea节点的高度
                    } = data; 
                    //如果设置的事件触发距离 大于等于 (节点的高度-屏幕高度-滚动条到顶部的距离)
                    if(this.bottomDistinct>=height-this.screenHeight-scrollTop){
                        //阻止事件重复触发
                        this.isLoading=true;
                        //模拟异步加载数据
                        uni.showToast({
                            title:"获取新数据"
                        })
                        setTimeout(()=>{
                            //测试数据
                            let arr=new Array(5).fill(0);
                            arr=arr.map((v,i)=>this.info.length+i+1);

                            //数据填充
                            this.info=this.info.concat(arr);
                            this.isLoading=false;
                        }, 1500);
                    }
                }).exec();
            }
        }
    }

完整demo代码

<template>
    <view class="content">
        <view class="text-area" id="listArea">
            <view class="square" v-for="(v,i) in info" :key='i'>{{v}}</view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                screenHeight: 0, //屏幕高度
                info: [],//展示的列表数据
                isLoading: false, //防止频繁触发
                bottomDistinct:200//距离底部多少像素时触发
            }
        },
        onLoad() {
            //页面加载时取得屏幕高度
            this.screenHeight = uni.getSystemInfoSync().screenHeight;
            //数据初始化
            this.info=new Array(5).fill(0).map((v,i)=>i+1);
        },
        methods: {
            /**
             *  页面滑动事件
             */
            onPageScroll: function(e) {
                const {
                    scrollTop//滚动条距离页面顶部的像素
                } = e;

                //防止重复触发
                if(this.isLoading){
                    return;
                }

                const query = uni.createSelectorQuery().in(this);
                query.select('#listArea').boundingClientRect(data => {
                    let {
                        height//listArea节点的高度
                    } = data; 
                    //如果设置的事件触发距离 大于等于 (节点的高度-屏幕高度-滚动条到顶部的距离)
                    if(this.bottomDistinct>=height-this.screenHeight-scrollTop){
                        //阻止时间重复触发
                        this.isLoading=true;
                        //模拟异步加载数据
                        uni.showToast({
                            title:"获取新数据"
                        })
                        setTimeout(()=>{
                            //测试数据
                            let arr=new Array(5).fill(0);
                            arr=arr.map((v,i)=>this.info.length+i+1);

                            //数据填充
                            this.info=this.info.concat(arr);
                            this.isLoading=false;
                        }, 1500);
                    }
                }).exec();
            }
        }
    }
</script>

<style>

    .text-area {
        display: flex;
        justify-content: center;
        flex-direction: column;
        align-items: center;
        background-color: #007AFF;
    }
    .square{
        margin: 1em;
        background-color: #4CD964;
        color: #fff;
        width:8em;
        text-align: center;
        line-height: 5em;
        height: 5em;
    }

</style>

监听页面滚动事件:

获取节点信息

onPageScroll
uni.createSelectorQuery()