9
9
vue 懒加载容器,通过监听元素在页面中的可见性,决定是否加载资源并渲染。
10
10
11
11
## 解决什么问题
12
+
12
13
当页面内容超过一屏时,我们往往希望只加载并渲染当前一屏的数据,而随着页面的滚动,再去加载并渲染下面的内容。这样的好处可以大大提升页面打开速度,以及减少额外的网络请求(xhr)。vue-lazy-container 正好可以帮我们解决这个问题。
13
14
14
15
## Online Demo
@@ -40,7 +41,7 @@ Vue.use(VueLazyContainer);
40
41
41
42
``` javascript
42
43
< template>
43
- < vue- lazy- container tag- name= " div" @change= " visibilityChange" >
44
+ < vue- lazy- container tag- name= " div" id = 1 @change= " visibilityChange" >
44
45
< template v- if = " isLoaded" >
45
46
<!-- your content -->
46
47
< / template>
@@ -56,7 +57,7 @@ export default {
56
57
},
57
58
methods: {
58
59
// visibility change
59
- visibilityChange (entry , observer ) {
60
+ visibilityChange (entry , observer , id ) {
60
61
const { isIntersecting } = entry;
61
62
62
63
// visibility
@@ -75,17 +76,17 @@ export default {
75
76
76
77
** Props**
77
78
78
- | 参数 | 说明 | 类型 | 可选值 | 默认值 |
79
- | ------- | ------------ | ----------------- | ---------------------------- | ------ |
80
- | tagName | 容器节点类型 | ` Element.tagName ` | div、span、p、img、i、a etc. | - |
81
- | intersectionOption | Intersection Observer Option | ` Object ` | root、rootMargin、threshold | - |
82
-
79
+ | 参数 | 说明 | 类型 | 可选值 | 默认值 |
80
+ | ------------------ | ---------------- ------------ | ----------------- | ---------------------------- | ------ |
81
+ | tagName | 容器节点类型 | ` Element.tagName ` | div、span、p、img、i、a etc. | - |
82
+ | id | 容器的 id | ` String, Number ` | - | - |
83
+ | intersectionOption | Intersection Observer Option | ` Object ` | root、rootMargin、threshold | - |
83
84
84
85
** Event**
85
86
86
- | 事件名称 | 说明 | 回调参数 |
87
- | -------- | ------------ | ---------- |
88
- | change | 元素可见变化事件 | [ IntersectionObserverEntry] ( https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry ) 、observer |
87
+ | 事件名称 | 说明 | 回调参数 |
88
+ | -------- | ---------------- | ------------------------------------------------------------------------------------------------------- ---------- |
89
+ | change | 元素可见变化事件 | [ IntersectionObserverEntry] ( https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry ) 、observer、id |
89
90
90
91
## License
91
92
0 commit comments