perf(@vant/lazyload): reduce production log

This commit is contained in:
chenjiahan 2021-09-24 10:38:57 +08:00 committed by neverland
parent 00b1568887
commit 33d7aa8f1a
3 changed files with 22 additions and 8 deletions

View File

@ -80,10 +80,15 @@ export default (lazyManager) => ({
}, },
load(onFinish = noop) { load(onFinish = noop) {
if (this.state.attempt > this.options.attempt - 1 && this.state.error) { if (this.state.attempt > this.options.attempt - 1 && this.state.error) {
if (!lazyManager.options.silent) if (
process.env.NODE_ENV !== 'production' &&
!lazyManager.options.silent
) {
console.log( console.log(
`VueLazyload log: ${this.options.src} tried too more than ${this.options.attempt} times` `[@vant/lazyload] ${this.options.src} tried too more than ${this.options.attempt} times`
); );
}
onFinish(); onFinish();
return; return;
} }

View File

@ -472,8 +472,14 @@ export default function () {
// value is object // value is object
if (isObject(value)) { if (isObject(value)) {
if (!value.src && !this.options.silent) if (
console.error('Vue Lazyload warning: miss src with ' + value); process.env.NODE_ENV !== 'production' &&
!value.src &&
!this.options.silent
) {
console.error('[@vant/lazyload] miss src with ' + value);
}
({ src } = value); ({ src } = value);
loading = value.loading || this.options.loading; loading = value.loading || this.options.loading;
error = value.error || this.options.error; error = value.error || this.options.error;

View File

@ -140,9 +140,10 @@ export default class ReactiveListener {
// handler `loading image` load failed // handler `loading image` load failed
cb(); cb();
this.state.loading = false; this.state.loading = false;
if (!this.options.silent)
if (process.env.NODE_ENV !== 'production' && !this.options.silent)
console.warn( console.warn(
`VueLazyload log: load failed with loading image(${this.loading})` `[@vant/lazyload] load failed with loading image(${this.loading})`
); );
} }
); );
@ -154,10 +155,12 @@ export default class ReactiveListener {
*/ */
load(onFinish = noop) { load(onFinish = noop) {
if (this.attempt > this.options.attempt - 1 && this.state.error) { if (this.attempt > this.options.attempt - 1 && this.state.error) {
if (!this.options.silent) if (process.env.NODE_ENV !== 'production' && !this.options.silent) {
console.log( console.log(
`VueLazyload log: ${this.src} tried too more than ${this.options.attempt} times` `[@vant/lazyload] ${this.src} tried too more than ${this.options.attempt} times`
); );
}
onFinish(); onFinish();
return; return;
} }