Skip to content

Commit

Permalink
fix: lazy loading on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuk1ko committed Apr 17, 2024
1 parent 89418de commit 1d4feea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/components/DataImg.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<img
:src="imgSrc"
:style="imgStyle"
:loading="lazy ? 'lazy' : undefined"
:loading="loading"
crossorigin="anonymous"
@error="isError = true"
/>
Expand All @@ -13,6 +13,7 @@ import { defineComponent } from 'vue';
import { mapState } from 'pinia';
import { useHotUpdateStore } from '@/store/hotUpdate';
import { PNG1P } from '@/utils/constant';
import { IS_IOS } from '@/utils/env';
const defaultErrorStyle = {
backgroundColor: '#bdbdbd',
Expand Down Expand Up @@ -45,6 +46,10 @@ export default defineComponent({
if (!this.isError) return;
return this.errorStyle === true ? defaultErrorStyle : this.errorStyle;
},
loading() {
// iOS PWA image lazy loading failed bug
return !IS_IOS && this.lazy ? 'lazy' : undefined;
},
},
methods: {
handleError(e) {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const IS_DEV = process.env.NODE_ENV === 'development';

export const IS_MOBILE = /Mobile|Android|webOS|iPhone|iPad|Phone/i.test(navigator.userAgent);
export const IS_MOBILE = /Mobile|Android|Phone|iPad|webOS/.test(navigator.userAgent);

export const IS_IOS = /iPhone|iPad/.test(navigator.userAgent);

0 comments on commit 1d4feea

Please sign in to comment.