MCPcopy
hub / github.com/youzan/vant / add

Method add

packages/vant/src/lazyload/vue-lazyload/lazy.js:128–179  ·  view source on GitHub ↗
(el, binding, vnode)

Source from the content-addressed store, hash-verified

126 * @return
127 */
128 add(el, binding, vnode) {
129 if (this.listeners.some((item) => item.el === el)) {
130 this.update(el, binding);
131 return nextTick(this.lazyLoadHandler);
132 }
133
134 const value = this.valueFormatter(binding.value);
135 let { src } = value;
136
137 nextTick(() => {
138 src = getBestSelectionFromSrcset(el, this.options.scale) || src;
139 this.observer && this.observer.observe(el);
140
141 const container = Object.keys(binding.modifiers)[0];
142 let $parent;
143
144 if (container) {
145 $parent = vnode.context.$refs[container];
146 // if there is container passed in, try ref first, then fallback to getElementById to support the original usage
147 $parent = $parent
148 ? $parent.$el || $parent
149 : document.getElementById(container);
150 }
151
152 if (!$parent) {
153 $parent = getScrollParent(el);
154 }
155
156 const newListener = new ReactiveListener({
157 bindType: binding.arg,
158 $parent,
159 el,
160 src,
161 loading: value.loading,
162 error: value.error,
163 cors: value.cors,
164 elRenderer: this.elRenderer.bind(this),
165 options: this.options,
166 imageCache: this.imageCache,
167 });
168
169 this.listeners.push(newListener);
170
171 if (inBrowser) {
172 this.addListenerTarget(window);
173 this.addListenerTarget($parent);
174 }
175
176 this.lazyLoadHandler();
177 nextTick(() => this.lazyLoadHandler());
178 });
179 }
180
181 /**
182 * update image src

Callers 12

updateMethod · 0.95
snapshotDemoFunction · 0.45
useFunction · 0.45
addThemeFunction · 0.45
lockFunction · 0.45
loadMethod · 0.45
updateMethod · 0.45
lockClickFunction · 0.45
initDemoLocaleFunction · 0.45
useTranslateFunction · 0.45
searchFunction · 0.45
addFunction · 0.45

Calls 8

updateMethod · 0.95
valueFormatterMethod · 0.95
addListenerTargetMethod · 0.95
lazyLoadHandlerMethod · 0.95
getScrollParentFunction · 0.90
observeMethod · 0.80
bindMethod · 0.80

Tested by

no test coverage detected