Skip to content

Commit

Permalink
feat: img lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Sep 22, 2023
1 parent ec6fe2c commit 0b9d646
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 233 deletions.
8 changes: 7 additions & 1 deletion components/layout/header/Content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ const userStore = useUserStore()
/>
<div class="header">
<div class="logo-container" @click="navigateTo('/')">
<img src="~assets/img/logo.svg" draggable="false" class="logo" />
<NuxtImg
src="/img/logo.svg"
draggable="false"
class="logo"
loading="lazy"
preload
/>
<span class="name"> 审核员中心 </span>
</div>
<div class="menu">
Expand Down
4 changes: 3 additions & 1 deletion components/layout/header/account/AccountInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const userStore = useUserStore()
<div class="account" :class="props.class">
<span class="username"> {{ userStore.user?.name }} </span>
<div class="avatar-wrapper">
<img
<NuxtImg
:src="getAvatarURL(userStore.user?.email || '')"
draggable="false"
class="avatar"
loading="lazy"
placeholder
/>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion components/mobile/MenuDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const userStore = useUserStore()
>
<div class="drawer-container">
<div class="account-container">
<img
<NuxtImg
:src="getAvatarURL(userStore.user?.email || '')"
draggable="false"
loading="lazy"
placeholder
class="avatar"
/>
<div class="main">
Expand Down
4 changes: 3 additions & 1 deletion components/poll/Comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ const render = (record: PollDetailRes['records'][0]): string => {
<template v-for="record in records" :key="record.user.id">
<div class="comment">
<div class="avatar">
<img
<NuxtImg
:src="getAvatarURLByHash(record.user.email_hash)"
:draggable="false"
loading="lazy"
placeholder
/>
</div>
<div class=":uno: flex-1 flex flex-col justify-center">
Expand Down
6 changes: 4 additions & 2 deletions layouts/auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ watchEffect(() => {
'logo-bg': !background
}"
></div>
<img
src="~assets/img/logo.svg"
<NuxtImg
src="/img/logo.svg"
draggable="false"
class="logo w-18 h-18"
preload
loading="lazy"
/>
</div>

Expand Down
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default defineNuxtConfig({
'~/assets/scss/main.scss'
],
modules: [
'@nuxt/image',
'@unocss/nuxt',
// Doc: https://color-mode.nuxtjs.org/
'@nuxtjs/color-mode',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"xss": "^1.0.14"
},
"dependencies": {
"@nuxt/image": "1.0.0-rc.2",
"@types/lodash-es": "^4.17.9",
"lodash-es": "^4.17.21"
}
Expand Down
10 changes: 8 additions & 2 deletions pages/dashboard/apply_reviewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ const apply = async () => {
href="https://cdn.a632079.me/assets/images/202309040813220.png"
target="_blank"
>
<img src="https://cdn.a632079.me/assets/images/202309040813220.png"
/></a>
<NuxtImg
src="https://cdn.a632079.me/assets/images/202309040813220.png"
draggable="false"
class="w-full md:w-90% mx-auto block"
loading="lazy"
placeholder
/>
</a>
<p>
审核员模块
<a
Expand Down
Loading

0 comments on commit 0b9d646

Please sign in to comment.