mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Lazyload): directive update is removed
This commit is contained in:
parent
b6a9245740
commit
5d8b7bd7fb
@ -26,8 +26,7 @@ export const Lazyload = {
|
|||||||
|
|
||||||
app.directive('lazy', {
|
app.directive('lazy', {
|
||||||
beforeMount: lazy.add.bind(lazy),
|
beforeMount: lazy.add.bind(lazy),
|
||||||
update: lazy.update.bind(lazy),
|
updated: lazy.update.bind(lazy),
|
||||||
updated: lazy.lazyLoadHandler.bind(lazy),
|
|
||||||
unmounted: lazy.remove.bind(lazy),
|
unmounted: lazy.remove.bind(lazy),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -9,14 +9,16 @@ export default (lazy) => {
|
|||||||
default: 'div',
|
default: 'div',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
emits: ['show'],
|
emits: ['show'],
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return h(
|
return h(
|
||||||
this.tag,
|
this.tag,
|
||||||
null,
|
|
||||||
this.show && this.$slots.default ? this.$slots.default() : null
|
this.show && this.$slots.default ? this.$slots.default() : null
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
el: null,
|
el: null,
|
||||||
@ -27,18 +29,22 @@ export default (lazy) => {
|
|||||||
show: false,
|
show: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.el = this.$el;
|
this.el = this.$el;
|
||||||
lazy.addLazyBox(this);
|
lazy.addLazyBox(this);
|
||||||
lazy.lazyLoadHandler();
|
lazy.lazyLoadHandler();
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
lazy.removeComponent(this);
|
lazy.removeComponent(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
getRect() {
|
getRect() {
|
||||||
this.rect = this.$el.getBoundingClientRect();
|
this.rect = this.$el.getBoundingClientRect();
|
||||||
},
|
},
|
||||||
|
|
||||||
checkInView() {
|
checkInView() {
|
||||||
this.getRect();
|
this.getRect();
|
||||||
return (
|
return (
|
||||||
@ -49,11 +55,13 @@ export default (lazy) => {
|
|||||||
this.rect.right > 0
|
this.rect.right > 0
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
this.show = true;
|
this.show = true;
|
||||||
this.state.loaded = true;
|
this.state.loaded = true;
|
||||||
this.$emit('show', this);
|
this.$emit('show', this);
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
return this.$destroy;
|
return this.$destroy;
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user