{"id":13637792,"url":"https://github.com/o2team/wxapp-img-loader","last_synced_at":"2025-05-16T18:10:18.047Z","repository":{"id":50447062,"uuid":"78162319","full_name":"o2team/wxapp-img-loader","owner":"o2team","description":"适用于微信小程序的图片预加载组件","archived":false,"fork":false,"pushed_at":"2020-07-27T23:29:46.000Z","size":90,"stargazers_count":1111,"open_issues_count":4,"forks_count":232,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-04-12T17:46:27.507Z","etag":null,"topics":["wechat","wechat-app","wxapp"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/o2team.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":"2017-01-06T01:24:27.000Z","updated_at":"2025-03-10T07:01:46.000Z","dependencies_parsed_at":"2022-09-05T15:30:52.620Z","dependency_job_id":null,"html_url":"https://github.com/o2team/wxapp-img-loader","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/o2team%2Fwxapp-img-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o2team%2Fwxapp-img-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o2team%2Fwxapp-img-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o2team%2Fwxapp-img-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/o2team","download_url":"https://codeload.github.com/o2team/wxapp-img-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582907,"owners_count":22095518,"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":["wechat","wechat-app","wxapp"],"created_at":"2024-08-02T01:00:33.092Z","updated_at":"2025-05-16T18:10:18.024Z","avatar_url":"https://github.com/o2team.png","language":"JavaScript","funding_links":[],"categories":["组件","UI组件","UI模板"],"sub_categories":["3、小程序模板"],"readme":"# wxapp-img-loader\n\n这是一个适用于微信小程序的原生图片预加载组件（**若你使用的是 [Taro](https://taro.aotu.io/)，请移步至 [taro 分支](https://github.com/o2team/wxapp-img-loader/tree/taro)**），已应用于京东购物等多个小程序中。使用步骤如下：\n\n1、将 img-loader 目录拷贝到你的项目中\n\n2、在页面的 WXML 文件中添加以下代码，将组件模板引入\n\n```html\n\u003cimport src=\"../../img-loader/img-loader.wxml\"/\u003e\n\u003ctemplate is=\"img-loader\" data=\"{{ imgLoadList }}\"\u003e\u003c/template\u003e\n```\n\n3、在页面的 JS 文件中引入组件脚本\n\n```js\nconst ImgLoader = require('../../img-loader/img-loader.js')\n```\n\n4、实例化一个 ImgLoader 对象，将 this(当前 Page 对象) 传入，第二个参数可选，为默认的图片加载完成的回调方法\n\n```js\nthis.imgLoader = new ImgLoader(this)\n```\n\n5、调用 ImgLoader 实例的 load 方法进行图片加载，第一个参数为图片链接，第二个参数可选，为该张图片加载完成时的回调方法\n\n```js\nthis.imgLoader.load(imgUrlOriginal, (err, data) =\u003e {\n    console.log('图片加载完成', err, data.src, data.width, data.height)\n})\n```\n\n注：图片加载完成的回调方法的第一个参数为错误信息（加载成功则为 null），第二个参数为图片信息（Object 类型，包括 src、width 及 height）。\n\n使用方法可参考 demo 目录的事例，包括加载单张图片、及加载多张图片的场景，运行效果如下图所示：\n\n![单张图片预加载](http://storage.360buyimg.com/mtd/home/single-img-load1483686270312.gif)\n![多张图片预加载](http://storage.360buyimg.com/mtd/home/multi-img-load1483686388552.gif)\n\n\\- eof -\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo2team%2Fwxapp-img-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fo2team%2Fwxapp-img-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo2team%2Fwxapp-img-loader/lists"}