99vue 懒加载容器,通过监听元素在页面中的可见性,决定是否加载资源并渲染。
1010
1111## 解决什么问题
12+
1213当页面内容超过一屏时,我们往往希望只加载并渲染当前一屏的数据,而随着页面的滚动,再去加载并渲染下面的内容。这样的好处可以大大提升页面打开速度,以及减少额外的网络请求(xhr)。vue-lazy-container 正好可以帮我们解决这个问题。
1314
1415## Online Demo
@@ -40,7 +41,7 @@ Vue.use(VueLazyContainer);
4041
4142``` javascript
4243< template>
43- < vue- lazy- container tag- name= " div" @change= " visibilityChange" >
44+ < vue- lazy- container tag- name= " div" id = 1 @change= " visibilityChange" >
4445 < template v- if = " isLoaded" >
4546 <!-- your content -->
4647 < / template>
@@ -56,7 +57,7 @@ export default {
5657 },
5758 methods: {
5859 // visibility change
59- visibilityChange (entry , observer ) {
60+ visibilityChange (entry , observer , id ) {
6061 const { isIntersecting } = entry;
6162
6263 // visibility
@@ -75,17 +76,17 @@ export default {
7576
7677** Props**
7778
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 | - |
8384
8485** Event**
8586
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 |
8990
9091## License
9192
0 commit comments