# taro-preload

> taro component, preload image everywhere

Latest version **1.1.2** (published 2020-08-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install taro-preload
pnpm add taro-preload
yarn add taro-preload
bun add taro-preload
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2020-08-27 |
| First published | 2020-08-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ksora |
| Maintainers | ksora |
| Keywords | taro, preload, taro-preload, image, miniapp |

## Links

- npm: https://www.npmjs.com/package/taro-preload
- Repository: https://github.com/ksora94/taro-preload
- Homepage: https://github.com/ksora94/taro-preload#readme
- Issues: https://github.com/ksora94/taro-preload/issues
- npm.io page: https://npm.io/package/taro-preload

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2020-08-27
- 1.1.1 — 2020-08-27
- 1.1.0 — 2020-08-27
- 1.0.3 — 2020-08-25
- 1.0.2 — 2020-08-25
- 1.0.1 — 2020-08-25
- 1.0.0 — 2020-08-25

## README

# Taro小程序图片预加载组件

## 安装
```
npm install taro-preload
```

## 使用
在小程序首页，或者初始页面（进入小程序的第一个页面）引入Preload组件。

_可以在不同页面重复引入，不会重复执行预加载的操作_
```tsx
import Taro, { Component } from '@tarojs/taro'
import {Preload} from 'taro-preload';

export default class Index extends Component{
  render () {
    return (
      <View className='index'>
        ...

        <Preload/>
      </View>
    )
  }
}
```

确保Preload组件挂载成功后，在任何页面，任何地方，都可以调用预加载命令。
```tsx
import {preload} from 'taro-preload';

preload(['img1', 'img2']).then(() => {
  console.log('预加载结束')
})
```

### API
function preload(data: string[], timeout?: number): Promise<Task>

data: 图片链接列表

timeout: 图片加载超时时间，默认1500ms，如果<0则不进行超时判断

Task.length: 需要加载的图片数量

Task.count: 未加载结束的图片数量

Task.loaded: 加载成功的图片列表

Task.error: 加载失败的图片列表

---
_Source: https://npm.io/package/taro-preload · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
