{"id":14976472,"url":"https://github.com/yujinjin/list-pull-loading","last_synced_at":"2025-10-27T20:31:54.915Z","repository":{"id":30181625,"uuid":"124171818","full_name":"yujinjin/list-pull-loading","owner":"yujinjin","description":"list-pull-loading是一个基于VUE实现的下拉刷新，上拉加载的组件。主使用IScroll（iscroll-probe）来实现，提供了项目中数据列表经常会用到的下拉提示信息、上拉提示信息、图片懒加载、回到顶部，其提示信息UI、内容可灵活配置，可使用提供的默认样式也可以自定义也可以隐藏。","archived":false,"fork":false,"pushed_at":"2022-12-12T19:10:26.000Z","size":1443,"stargazers_count":19,"open_issues_count":16,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-01T08:06:09.567Z","etag":null,"topics":["iscroll","iscroll-probe","list-pull-loading","listloading","vue2","webpack3"],"latest_commit_sha":null,"homepage":"https://yujinjin.github.io/list-pull-loading/#/","language":"Vue","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yujinjin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-07T03:12:23.000Z","updated_at":"2022-12-04T04:20:33.000Z","dependencies_parsed_at":"2023-01-14T16:29:32.802Z","dependency_job_id":null,"html_url":"https://github.com/yujinjin/list-pull-loading","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yujinjin%2Flist-pull-loading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yujinjin%2Flist-pull-loading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yujinjin%2Flist-pull-loading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yujinjin%2Flist-pull-loading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yujinjin","download_url":"https://codeload.github.com/yujinjin/list-pull-loading/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238553272,"owners_count":19491398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iscroll","iscroll-probe","list-pull-loading","listloading","vue2","webpack3"],"created_at":"2024-09-24T13:53:56.326Z","updated_at":"2025-10-27T20:31:54.555Z","avatar_url":"https://github.com/yujinjin.png","language":"Vue","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 前言\r\n[list-pull-loading](https://github.com/yujinjin/list-pull-loading)是一个基于VUE实现的下拉刷新，上拉加载的组件，支持图片懒加载，数据缓存（返回列表页记住当前位置）。主使用IScroll（iscroll-probe）来实现，提供了项目中数据列表经常会用到的下拉提示信息、上拉提示信息、图片懒加载、回到顶部，其提示信息UI、内容可灵活配置，可使用提供的默认样式也可以自定义也可以隐藏。\r\n\r\n列表初始化时也做了优化，对于没有列表数据时显示没有数据的提示信息（可自定义），对于首次加载的数据没有超过一屏时会自动加载下一页的数据，但最多只会自动加载2次（可配置）。\r\n\r\n\r\n\r\n## 示例\r\ndemo使用了vue2+vuex3+vue-router3，对于图片懒加载使用的是vue-lazyload第三方插件。\r\n\r\n[首页](https://yujinjin.github.io/list-pull-loading/#/)\r\n\r\n![image](https://note.youdao.com/yws/public/resource/8cea9a8eae140b99ef9a0843d5a96d81/xmlnote/48BF2C9DD0B546779955D19222F1D8FA/4296)\r\n\r\n[示例一](https://yujinjin.github.io/list-pull-loading/#/demo1)\r\n\r\n![image](https://note.youdao.com/yws/public/resource/8cea9a8eae140b99ef9a0843d5a96d81/xmlnote/040A526107FE42D28DC0C671084467A0/3908)\r\n\r\n说明：普通示例\r\n\r\n[示例二](https://yujinjin.github.io/list-pull-loading/#/demo2)\r\n\r\n![image](https://note.youdao.com/yws/public/resource/8cea9a8eae140b99ef9a0843d5a96d81/xmlnote/4AAE2CB68982409A95EBEE1F9476CA3C/3915)\r\n\r\n说明：多个tap分类数据列表\r\n\r\n[示例三](https://yujinjin.github.io/list-pull-loading/#/demo3)\r\n\r\n![image](https://note.youdao.com/yws/public/resource/8cea9a8eae140b99ef9a0843d5a96d81/xmlnote/105DA40582E24A91B11BF663F9173F0F/3918)\r\n\r\n说明：数据列表中有图片而且图片还使用了懒加载的方式。\r\n\r\n[示例四](https://yujinjin.github.io/list-pull-loading/#/demo4)\r\n\r\n![image](https://note.youdao.com/yws/public/resource/8cea9a8eae140b99ef9a0843d5a96d81/xmlnote/6749738410B64D9696EA2A6563BCA338/3923)\r\n\r\n说明：数据列表中的链接跳转到其它页面，再返回时自动加载到上一次看到的状态位置。\r\n\r\n## 运行项目\r\nclone项目到本地，进入项目文件夹，安装依赖\r\n\r\n```javascript\r\ngit clone https://github.com/yujinjin/list-pull-loading.git\r\ncd list-pull-loading\r\nnpm install\r\n```\r\n运行demo，会自动打开浏览器地址运行\r\n```javascript\r\nnpm run demo\r\n```\r\n编译打包项目\r\n```javascript\r\nnpm run compile\r\n```\r\n\r\n## NPM\r\n```javascript\r\nnpm install list-pull-loading\r\n```\r\n## 依赖\r\n- VUE\r\n- IScroll(iscroll-probe)\r\n## CDN\r\nhttps://apps.bdimg.com/libs/list-pull-loading/1.0.0/list-pull-loading.js\r\n\r\nhttps://apps.bdimg.com/libs/list-pull-loading/1.0.0/list-pull-loading.css\r\n```html\r\n\u003cscript src=\"https://apps.bdimg.com/libs/list-pull-loading/1.0.0/list-pull-loading.js\"\u003e\u003c/script\u003e\r\n\u003clink href=\"https://apps.bdimg.com/libs/list-pull-loading/1.0.0/list-pull-loading.css\" rel=\"stylesheet\"\u003e\r\n\u003cscript\u003e\r\n  Vue.use(ListPullLoading)\r\n  ...\r\n\u003c/script\u003e\r\n```\r\n## 使用\r\n作为插件\r\n```javascript\r\nimport Vue from 'vue'\r\nimport ListPullLoading from 'list-pull-loading'\r\nimport 'list-pull-loading/dist/list-pull-loading.css'\r\n\r\n// VUE use\r\nVue.use(ListPullLoading);\r\n// or with options\r\nVue.use(ListPullLoading, {\r\n    isLoading: false, // API是否正在加载\r\n    hasData: true, // 当前列表是否有数据\r\n    downElHeight: 0, // 下拉元素的高度\r\n\tupElHeight: 0, // 上拉提示元素的高度\r\n\tscrollerMinHeight: 0, //当前容器最小高度\r\n\tdirectionY: 0, // -1:up 上, 1: down下\r\n\tstartPullTime: 0, // 开始下拉的时间\r\n\tendPullTime: 0, // 结束下拉的时间\r\n\tlastQueryTime: 0, // 最后一次查询的时间\r\n\tisCanToTop: false, // 根据当前滚动位置判断是否能调到顶部\r\n\tisShowToTop: true, // 是否显示去顶部图标\r\n\tinitMaxTimes: 3, // 初始化数据不够一屏最大查询次数\r\n\tnoDataText: \"没有找到相关的内容哦~\", // 没有列表数据时的内容展示\r\n\tmyScroll: null, // 当前iScroll实例\r\n\tapi: null, // 当前数据列表API查询接口\r\n\tauto: true, // 是否自动查询\r\n\t// 图片自适应，默认为false。最好不要设置为true，因为比较消耗资源。\r\n\t// 原因是：true的情况下是应用于列表数据里有懒加载的图片但没有指定图片大小导致iScroll计算高度不准确需要的等图片加载完之后再重新计算高度。\r\n\t// 目前都是通过监控图片的onload事件来刷新的这样真的不爽但也没找到其他好的解决方案，所以最好是列表中有图片加载时就预先把高度写死\r\n\timgResize: false, \r\n\tiScrollOptions: {\r\n\t\tprobeType: 3, //必须指定为3，否则拖动太快就监控不到\r\n\t\tmouseWheel: false,\r\n\t\tdisableMouse: true,\r\n\t\tscrollbars: false,\r\n\t\tpreventDefault: true\r\n\t\tstartY: 0\r\n\t}, //IScroll选项\r\n\tdown: {\r\n\t\toffset: 50, //列表下拉滚动大于50px,即可触发下拉刷新的回调\r\n\t\tinitText: \"下拉刷新\", //初始化文案，这个是在当前下来滚动未超过指定的值时显示文案\r\n\t\tnotReleaseText: \"松开刷新\", // 释放滚动加载时当前下拉高度还未回弹时的文案\r\n\t\tloadingText: \"正在加载更多\", // 正在加载时的文案\r\n\t\tstate: 0, //当前加载时的状态。0:初始化状态 1：未释放滚动加载时 2：正在加载时\r\n\t\tisShowLastTimeText: true // 是否显示最后更新时间提示 \r\n\t}, // 下拉刷新\r\n\tup: {\r\n\t\toffset: 50, //列表上拉滚动大于50px,即可触发上拉加载的回调\r\n\t\tinitText: \"上拉加载更多\", //初始化文案，当前上拉高度未超过指定的高度时\r\n\t\tnotReleaseText: \"松开加载更多\", // 未释放滚动加载时的文案，当前上拉高度超过指定的高度时且还未释放滚动\r\n\t\tloadingText: \"正在加载更多\", // 正在加载时的文案\r\n\t\tnoMoreText: \"没有更多数据了...\", // 没有数据时的文案\r\n\t\tstate: 0, //当前加载时的状态。0:初始化状态 1：未释放滚动加载时 2：正在加载时 3: 没有更多数据了\r\n\t}, // 上拉加载\r\n\tparameters: {\r\n\t\tmaxResultCount: 20, //每次分页数据加载多少条\r\n\t\tskipCount: 0 //每次数据偏移\r\n\t} // 数据查询参数\r\n});\r\n```\r\n作为组件\r\n```javascript\r\nimport Vue from 'vue'\r\nimport {listPullLoading} from 'list-pull-loading'\r\nimport \"list-pull-loading/dist/list-pull-loading.css\"\r\n\r\nnew Vue({\r\n    // ...\r\n    components: {\r\n        \"list-pull-loading\": listPullLoading\r\n    }\r\n})\r\n```\r\nview层举例\r\n```html\r\n\u003clist-pull-loading :options=\"options\" ref=\"listPullLoading\"\u003e\r\n    \u003c!-- 自定义下拉刷新(不写就显示默认的) --\u003e\r\n    \u003ctemplate slot=\"down\"\u003e\r\n        ...\r\n    \u003c/template\u003e\r\n    \u003c!-- 数据列表 --\u003e\r\n\t\u003ctemplate slot=\"list\"\u003e\r\n\t\t\u003cul\u003e\r\n\t\t\t\u003cli v-for=\"(dataItem,dataIndex) in dataList\" :key=\"dataItem.id\"\u003e\r\n\t\t\t\t\u003ca\u003e\r\n\t\t\t\t\t...\r\n\t\t\t\t\u003c/a\u003e\r\n\t\t\t\u003c/li\u003e\r\n\t\t\u003c/ul\u003e\r\n\t\u003c/template\u003e\r\n\t\u003c!-- 自定义没有数据时显示的内容(不写就显示默认的) --\u003e\r\n\t \u003ctemplate slot=\"nodata\"\u003e\r\n        ...\r\n    \u003c/template\u003e\r\n    \u003c!-- 自定义上拉加载显示(不写就显示默认的) --\u003e\r\n\t \u003ctemplate slot=\"up\"\u003e\r\n        ...\r\n    \u003c/template\u003e\r\n\u003c/list-pull-loading\u003e\r\n```\r\n注意\r\n1. 由于组件使用了IScrol（iscroll-probe）来实现如果项目中是通过webpack来引入IScrol包一定要在webpack.config里配置IScrol的alias，具体如下：\r\n```javascript\r\n...\r\n    resolve: {\r\n        alias: {\r\n            iscroll: 'iscroll/build/iscroll-probe'\r\n        }\r\n    }\r\n...\r\n```\r\n2. 部分老androd机可能会有卡顿现象，建议加入以下css属性样式来提升硬件加速\r\n```css\r\n* {\r\n    -webkit-overflow-scrolling: touch;\r\n}\r\n```\r\n3. 发现在chrome浏览器中模拟webapp运行时鼠标滑动很不流畅，原因是新谷歌浏览滚动条的阻止默认事件会失效,所以得所有滚动区域都要加上touch-action:none 来解决。\r\n```css\r\n{\r\n    ...\r\n    touch-action: none;\r\n    ...\r\n}\r\n```\r\n4. 由于list-pull-loading组件的滚动不是body上滚动而是在内部盒子里滚动，所以在定义内部的盒子高度，特别是页面内局部滚动。\r\n\r\n![image](https://note.youdao.com/yws/public/resource/8cea9a8eae140b99ef9a0843d5a96d81/xmlnote/16E8C8F333944E5C9C65A572EA0A29A6/4167)\r\n\r\n## 配置选项\r\n\r\n名称 | 描述 | 默认值 | 可选项\r\n---|---|---|---\r\n`isShowToTop` | 是否显示去顶部图标，默认显示 | `true` | `Boolean`\r\n`initMaxTimes` | 初始化列表数据时，如果当前有足够的列表数据但查询的数据不足以覆盖到当前容器的底部会自动进行下一页数据加载，最多自动加载3次（包含初次）。\u003cbr\u003e\u003cbr\u003e比如：数据初始化时每次只查询出5条数据，但实际当前的容器盒子需要13条数据才会覆盖到底部，这个时候组件会自动判断如果没有覆盖到底部会自动加载下一页。| `3` | `Number`\r\n`noDataText` | 没有列表数据时的文案展示 | `没有找到相关的内容哦~` | `String`\r\n`api` | 当前数据列表API函数，会传入2个参数，parameters：当前列表查询参数, isLoadingMore：是否是重新加载。**函数的返回值必须是Promise类型，而且是必须配置，如果不配置会抛出\"错误的API\"异常**。 | `null` | `Function`\r\n`auto` | 是否自动查询，默认初始化会自动加载API数据 | `true` | `Boolean`\r\n`imgResize` | 是否自动查询图片自适应，默认为false。最好不要设置为true，因为比较消耗资源。\u003cbr\u003e\u003cbr\u003e原因是：true的情况下是应用于列表数据里有懒加载的图片但没有指定图片大小导致iScroll计算高度不准确需要的等图片加载完之后再重新计算高度。\u003cbr\u003e\u003cbr\u003e当前都是通过监控图片的onload事件来刷新的，这样真的不爽但也没找到其他好的解决方案，所以最好是列表中有图片加载时就预先把高度预算好 | `true` | `Boolean`\r\n`iScrollOptions` | iscroll的配置选项。\u003cbr\u003e\u003cbr\u003e其中probeType的配置选项为3，否则拖动太快就监控不到。 | `{probeType: 3, mouseWheel: false, disableMouse: true, scrollbars: false, preventDefault: true, startY: 0}` | 具体可自行查询iscroll的[API](http://iscrolljs.com/)\r\n`down` | 下拉刷新配置选项，**如果为false就禁止下拉**。\u003cbr\u003e\u003cbr\u003eoffset：列表下拉滚动的偏移px数量(number类型),即可触发下拉刷新的回调\u003cbr\u003e\u003cbr\u003e initText：初始化文案，这个是在当前下来滚动未超过指定的值时显示文案 \u003cbr\u003e\u003cbr\u003enotReleaseText:释放滚动加载时当前下拉高度还未回弹时的文案\u003cbr\u003e\u003cbr\u003eloadingText:数据正在加载时的文案\u003cbr\u003e\u003cbr\u003estate:当前加载时的状态(number类型)。0:初始化状态 1：未释放滚动加载时 2：正在加载时\u003cbr\u003e\u003cbr\u003eisShowLastTimeText:是否显示最后更新时间提示| `down: {offset: 50, initText: \"下拉刷新\", notReleaseText: \"松开刷新\", loadingText: \"正在加载更多\", state: 0, isShowLastTimeText: true}` | `Object`\r\n`up` | 上拉加载配置选项，**如果为false就禁止上拉加载**。\u003cbr\u003e\u003cbr\u003eoffset：列表上拉加载滚动的偏移px数量(number类型),即可触发加载数据的回调\u003cbr\u003e\u003cbr\u003einitText：初始化文案，当上拉高度未超过指定的高度时\u003cbr\u003e\u003cbr\u003enotReleaseText:未释放滚动加载时的文案，当前上拉高度超过指定的高度时且还未释放滚动时。\u003cbr\u003e\u003cbr\u003eloadingText: 上拉API正在加载时的文案\u003cbr\u003e\u003cbr\u003enoMoreText:没有数据时的文案\u003cbr\u003e\u003cbr\u003estate:0:初始化状态 1：未释放滚动加载时 2：正在加载时 3: 没有更多数据了| `up: {offset: 50, initText: \"上拉加载更多\", notReleaseText: \"松开加载更多\", loadingText: \"正在加载更多\", noMoreText: \"没有更多数据了...\", state: 0}` | `Object`\r\n`parameters` | API数据参数，默认只有maxResultCount:每次分页数据加载多少条，skipCount:每次查询数据的开始索引2个参数 | `{maxResultCount: 20, skipCount: 0}` | `Object`\r\n\r\n## API\r\n###### 1. refresh\r\n刷新数据列表，有时根据实际的业务需要，需手动刷新列表数据。\r\n\r\n```javascript\r\nthis.$refs['listPullLoading'].refresh();//listPullLoading是组件注册引用名称\r\n```\r\n###### 2. initIScrollCacheData\r\n初始化列表的缓存数据，主要用于列表数据的缓存\r\n\r\n```javascript\r\nthis.$refs['listPullLoading'].initIScrollCacheData(y=0, upState=0);//y 当前滚动条的y轴位置，upState 当前下拉列表的状态\r\n```\r\n###### 3. destroy\r\n组件销毁\r\n\r\n## Event\r\n###### 1. scroll\r\n当前列表滚动时的事件。传入2个参数，listPullLoadingObject:当前组件对象，iscrollObject:当前组件内的iscroll对象\r\n\r\n```javascript\r\n\u003clist-pull-loading @scroll=\"scrolling\" ..\u003e\r\n```\r\n\r\n###### 2. scrollEnd\r\n当前列表滚动结束时的事件。传入2个参数，listPullLoadingObject:当前组件对象，iscrollObject:当前组件内的iscroll对象\r\n\r\n```javascript\r\n\u003clist-pull-loading @scrollEnd=\"scrollEnd\" ..\u003e\r\n```\r\n\r\n###### 3. down\r\n下拉刷新事件，iscrollObject:当前组件内的iscroll对象\r\n\r\n```javascript\r\n\u003clist-pull-loading @down=\"downEvent\" ..\u003e\r\n```\r\n\r\n###### 4. up\r\n上拉加载事件，iscrollObject:当前组件内的iscroll对象\r\n\r\n```javascript\r\n\u003clist-pull-loading @up=\"upEvent\" ..\u003e\r\n```\r\n\r\n## 最后\r\n- 如果喜欢一定要 star哈!!!（谢谢!!）\r\n\r\n- 如果有意见和问题 请在 lssues提出，我会在线解答。\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyujinjin%2Flist-pull-loading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyujinjin%2Flist-pull-loading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyujinjin%2Flist-pull-loading/lists"}