Socket
Socket
Sign inDemoInstall

mpvue-img-load

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mpvue-img-load

a image pre-load component for mpvue


Version published
Maintainers
1
Created
Source

mpvue-img-load

小程序图片预加载组件,基于 mpvue 框架的重写wxapp-img-loader,更好的满足工程化,模块化,自动化的需求

使用方式

1.安装依赖

npm install mpvue-img-load

2.调用组件

<div>
  <image v-if="imgUrl" :src="imgUrl" />
  <img-load ref="imgLoad"></img-load>
</div>
  import imgLoad from 'mpvue-img-load'

  export default {
    data () {
      return {
        imgUrl: ''
      }
    },
    components: {
      imgLoad
    },
    methods: {
      loadImage () {
        // 加载缩略图 80x50 3KB
        this.imgUrl = 'http://storage.360buyimg.com/mtd/home/lion1483683731203.jpg'
        // 原图 3200x2000 1.6MB
        const imgUrlOriginal = 'http://storage.360buyimg.com/mtd/home/lion1483624894660.jpg'
        // 同时对原图进行预加载,加载成功后再替换
        this.$refs.imgLoad.load(imgUrlOriginal, (err, data) => {
          if (!err) {
            this.imgUrl = data.src
          }
        })
      }
    }
  }

注: (1) load 方法进行图片加载,第一个参数为图片链接,第二个参数可选,为该张图片加载完成时的回调方法 (2)图片加载完成的回调方法的第一个参数为错误信息(加载成功则为 null),第二个参数为图片信息(Object 类型,包括 src、width 及 height)。 (3)demo运行效果如下图所示:

单张图片预加载 多张图片预加载

Keywords

FAQs

Package last updated on 24 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc