first commit
This commit is contained in:
51
node_modules/vant/es/lazyload/vue-lazyload/lazy-component.mjs
generated
vendored
Normal file
51
node_modules/vant/es/lazyload/vue-lazyload/lazy-component.mjs
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import { h } from "vue";
|
||||
import { inBrowser, useRect } from "@vant/use";
|
||||
var stdin_default = (lazy) => ({
|
||||
props: {
|
||||
tag: {
|
||||
type: String,
|
||||
default: "div"
|
||||
}
|
||||
},
|
||||
emits: ["show"],
|
||||
render() {
|
||||
return h(
|
||||
this.tag,
|
||||
this.show && this.$slots.default ? this.$slots.default() : null
|
||||
);
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
el: null,
|
||||
state: {
|
||||
loaded: false
|
||||
},
|
||||
show: false
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.el = this.$el;
|
||||
lazy.addLazyBox(this);
|
||||
lazy.lazyLoadHandler();
|
||||
},
|
||||
beforeUnmount() {
|
||||
lazy.removeComponent(this);
|
||||
},
|
||||
methods: {
|
||||
checkInView() {
|
||||
const rect = useRect(this.$el);
|
||||
return inBrowser && rect.top < window.innerHeight * lazy.options.preLoad && rect.bottom > 0 && rect.left < window.innerWidth * lazy.options.preLoad && rect.right > 0;
|
||||
},
|
||||
load() {
|
||||
this.show = true;
|
||||
this.state.loaded = true;
|
||||
this.$emit("show", this);
|
||||
},
|
||||
destroy() {
|
||||
return this.$destroy;
|
||||
}
|
||||
}
|
||||
});
|
||||
export {
|
||||
stdin_default as default
|
||||
};
|
||||
Reference in New Issue
Block a user