Skip to content

Commit 8d75070

Browse files
author
huangshuwei
committed
refine readme
1 parent 91f288f commit 8d75070

File tree

2 files changed

+95
-6
lines changed

2 files changed

+95
-6
lines changed

README-CN.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# vue-lazy-container
2+
3+
**中文** | [English](./README.md)
4+
5+
## Introduction
6+
7+
vue 懒加载容器,通过监听元素在页面中的可见性,决定是否加载资源并渲染。
8+
9+
## Why
10+
当页面内容超过一屏时,我们往往希望只加载并渲染当前一屏的数据,而随着页面的滚动,再去加载并渲染下面的内容。这样的好处可以大大提升页面打开速度,以及减少额外的网络请求(xhr)。vue-lazy-container 正好可以帮我们解决这个问题。
11+
12+
## Install
13+
14+
```
15+
npm install vue-lazy-container
16+
```
17+
18+
or
19+
20+
```
21+
yarn add vue-lazy-container
22+
```
23+
24+
## Usage
25+
26+
在你的 main.js 中写如下代码:
27+
28+
```javascript
29+
import VueLazyContainer from "vue-lazy-container";
30+
Vue.use(VueLazyContainer);
31+
```
32+
33+
示例:
34+
35+
```javascript
36+
<template>
37+
<vue-lazy-container tag-name="div" @change="visibilityChange">
38+
<template v-if="isLoaded">
39+
<!-- your content -->
40+
</template>
41+
</vue-lazy-container>
42+
</template>
43+
44+
<script>
45+
export default {
46+
data() {
47+
return {
48+
isLoaded: false
49+
};
50+
},
51+
methods: {
52+
// visibility change
53+
visibilityChange(entry, observer) {
54+
const { isIntersecting } = entry;
55+
56+
// visibility
57+
if (isIntersecting) {
58+
this.isLoaded = true;
59+
// you can ajax request or other logic
60+
}
61+
}
62+
}
63+
};
64+
</script>
65+
66+
```
67+
68+
## API
69+
70+
**Props**
71+
72+
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
73+
| ------- | ------------ | ----------------- | ---------------------------- | ------ |
74+
| tagName | 容器节点类型 | `Element.tagName` | div、span、p、img、i、a etc. | - |
75+
| intersectionOption | Intersection Observer Option | `Object` | root、rootMargin、threshold | - |
76+
77+
78+
**Event**
79+
80+
| 事件名称 | 说明 | 回调参数 |
81+
| -------- | ------------ | ---------- |
82+
| change | 元素可见变化事件 | [IntersectionObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry)、observer |

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# vue-lazy-container
22

3+
**English** | [中文](./README-CN.md)
4+
35
## Introduction
46

5-
Lazy container base on vuejs
7+
vue lazy container,By listening to the visibility of elements in the page, decide whether to load resources and render.
8+
9+
## Why
10+
When the page content exceeds one screen, we often want to load and render only the data of the current screen,As the page scrolls, load and render the following. This can greatly improve the speed of page opening,And reduce additional network requests(xhr)。vue-lazy-container can just help us solve this problem.
611

712
## Install
813

@@ -18,7 +23,7 @@ yarn add vue-lazy-container
1823

1924
## Usage
2025

21-
Write the following in your mian.js:
26+
Write the following in mian.js:
2227

2328
```javascript
2429
import VueLazyContainer from "vue-lazy-container";
@@ -64,12 +69,14 @@ export default {
6469

6570
**Props**
6671

67-
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
72+
| Prop | Description | Type | Optional value | Default |
6873
| ------- | ------------ | ----------------- | ---------------------------- | ------ |
69-
| tagName | 容器节点类型 | `Element.tagName` | div、span、p、img、i、a etc. | - |
74+
| tagName | Element TagName | `Element.tagName` | div、span、p、img、i、a etc. | - |
75+
| intersectionOption | Intersection Observer Option | `Object` | root、rootMargin、threshold | - |
76+
7077

7178
**Event**
7279

73-
| 事件名称 | 说明 | 回调参数 |
80+
| Event Name | Description | Callback Parameters |
7481
| -------- | ------------ | ---------- |
75-
| change | 容器节点类型 | 观察者列表 |
82+
| change | Element visible change events | [IntersectionObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry)、observer |

0 commit comments

Comments
 (0)