Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
fix: duplicate request in random image component
Browse files Browse the repository at this point in the history
  • Loading branch information
Gem Xli committed Mar 1, 2021
1 parent 36e5942 commit 0a36079
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
],
"rules": {
"space-before-function-paren": "off",
"no-unused-vars": "warn"
"no-unused-vars": "warn",

"vue/html-self-closing": "off"
}
}
13 changes: 8 additions & 5 deletions client/components/RandomImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class="img object-cover hidden w-full h-full object-center"
:class="{ block: !data.loading, visible: data.visible }"
@load="loaded"
>
/>
</div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref, watchEffect } from 'vue'
import { defineComponent, reactive, ref, watch } from 'vue'
import { axiosInstance } from '~/api'
import { useObserve } from '../hooks'
Expand Down Expand Up @@ -77,9 +77,12 @@ export default defineComponent({
const root = ref<any>(null)
watchEffect(async () => {
data.imgUrl = await getImageUrl(String(props.randomId), props.src)
})
watch(
() => props.randomId,
async () => {
data.imgUrl = await getImageUrl(String(props.randomId), props.src)
}
)
useObserve(root, async () => {
data.visible = true
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"release": "glib release"
},
"lint-staged": {
"*.{js,vue}": "eslint"
"*.{ts,js,vue}": "eslint"
},
"husky": {
"hooks": {
Expand Down

0 comments on commit 0a36079

Please sign in to comment.