1.1.0 • Published 4 years ago

mt-lazy-image v1.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

mt-lazy-image

A light-weight React mt-lazy-image component with extremely easy API(只适用于移动端项目). Online Demo, welcome code review

Installation

npm install mt-lazy-image --save

Usage mt-lazy-image

import React, { PureComponent } from 'react';
import './app.less';
import Image from 'mt-lazy-image'
import { data } from './constant';

export default class App extends PureComponent {
  constructor() {
    super();
    this.state = {
      source: [],
    }
    this.containRef = React.createRef(null);
  }

  componentDidMount() {
    this.setState({ source: data })
  }

  render() {
    return (
      <div className="container" >
        <ul className="mt-goods-list" ref={this.containRef}>
          {
            this.state.source.map(item =>
              <li className="mt-goods-list-item" key={item.goods_id}>
                <Image
                  src={item.url}
                  alt="商品图片"
                  className="mt-goods-list-item-avator"
                  container={this.containRef.current}
                />
                <div className="mt-goods-list-item-name">{item.name}</div>
                <div className="mt-goods-list-item-price">{(item.price / 100 || 0).toFixed(2)}</div>
                <div className="mt-goods-list-item-button">去抢购</div>
              </li>
            )
          }
        </ul>
      </div>
    );
  }
}

props

paramdetailtypedefault
classNameimg class namestring''
srcimg srcstringisRequired
defaultsrcimg default srcstring''
altimg altstring''
containerUnder which DOM node (overflow: auto / scroll)anywindow
propNameOther HTML attributes that can be set on the img elementany

注意

使用是需要注意 container props。这个props的值是一个设置了 overflow: auto | scroll 属性的 dom 元素

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago