首页 > 其他分享 >VUE 滚动到底部加载更多(附带指令实现方式)

VUE 滚动到底部加载更多(附带指令实现方式)

时间:2023-06-27 16:22:05浏览次数:43  
标签:VUE description DOM 附带 handleScroll SELECTWRAP 加载

VUE 滚动到底部加载更多(附带指令实现方式)

直接上代码:

    mounted() {  
          window.addEventListener('scroll', this.handleScroll, true);
    },
    destroyed() {
        window.removeEventListener('scroll', this.handleScroll);
    },
     methods: {
        /**
         * [handleScroll description]滚动到底部
         *
         * @param   {[type]}  e  [e description]
         *
         * @return  {[type]}     [return description]
         */
        handleScroll(e) {
            if (e.target.scrollTop + e.target.clientHeight >= e.target.scrollHeight) {
                //在此处放入你的加载更多方法
            }
        },
    }

效果:

用指令的方式更加方便

Vue.directive('drop-down-loadmore',{
    bind(el, binding) {
        const SELECTWRAP_DOM = el;
        SELECTWRAP_DOM.addEventListener('scroll', function() {
            const condition =
            SELECTWRAP_DOM.scrollHeight - SELECTWRAP_DOM.scrollTop <= SELECTWRAP_DOM.clientHeight;
            if (condition) {
                binding.value();
            }
        });
    }
});

 

标签:VUE,description,DOM,附带,handleScroll,SELECTWRAP,加载
From: https://www.cnblogs.com/panwudi/p/17509206.html

相关文章

  • 什么是 SAP UI5 应用运行时加载的 messagebundle_en.properties 文件?
    在SAPUI5应用程序中,messagebundle_en.properties文件是一个资源文件,用于存储应用程序的多语言文本和消息。这些消息通常包括用户界面中显示的标签、按钮文字、提示信息、错误消息等。使用资源文件的优势在于它可以轻松地使应用程序支持多种语言,同时保持代码的整洁和可维护性。......
  • 在线直播系统源码,uniapp滚动加载
    在线直播系统源码,uniapp滚动加载声明submitDate对象用来存放接口需要的具体参数,其中page和limit为查询页数和每页查询数据,total为记录数据总条数,pageList存放页面数据。     data(){return{  pageList:[],//列表数据submitDate:{//放你自己的参数startDate:''......
  • 直播开发app,vue防抖 自定义ref实现输入框防抖
    直播开发app,vue防抖自定义ref实现输入框防抖 首先需要把input的双向绑定v-mode拆开为一个value和一个input事件,在事件里注册一个函数debUpdata,debUpdata里获取到input输入内容再赋值给text,这就类似于手写v-mode,代码如下: <template> <divclass="hello">  <inpu......
  • 基于vue+elementUI使用vue-amap高德地图
    首先,需要去高德地图进行注册一个https://lbs.amap.com/?ref=https://console.amap.com/dev/index,得到一个key然后安装依赖npminstallvue-amap—save在main.js中加入importVueAMapfrom'vue-amap’;Vue.use(VueAMap);VueAMap.initAMapApiLoader({key:'YOUR_KEY’......
  • vue-element-admin 动态路由踩坑之路。。。
    参考帖子1.菜单详解(主要是加载原理,还有一些脚本,json格式的参考)https://blog.csdn.net/weixin_44922964/article/details/120927244https://blog.csdn.net/qq_57581439/article/details/1278629972.三级路由:https://www.cnblogs.com/netcore-vue/p/14911375.html(这个主要是加载......
  • vue3透传 Attributes
    “透传attribute”指的是传递给一个组件,却没有被该组件声明为props或emits的attribute或者 v-on 事件监听器。最常见的例子就是 class、style 和 id当一个组件以单个元素为根作渲染时,透传的attribute会自动被添加到根元素上A组件:<template><h3>ComponentA</......
  • Vue2电商实战项目(六)个人中心
    个人中心Center组件先搞定静态组件###router.routes.jsimportCenterfrom'@/pages/Center'exportdefault[ { name:"center", path:"/center", component:Center, meta:{ show:true } }......拆分Center组件,把我的订单和团购订单拆分成两个子路......
  • 【vue2】使用vue常见的业务流程与实现思路
     ......
  • Vue如何在页面加载时将url的参数赋值给组件
    <template> <inputv-model="loginForm.username" name="username" type="text" tabindex="1" auto-complete="on" /><inputv-model="loginForm.password":type="passwordType"......
  • 【vue2】vuex超超超级详解!(核心五大配置项)
    ......