Skip to content

Commit

Permalink
fix: watchEffect副作用
Browse files Browse the repository at this point in the history
  • Loading branch information
Plumbiu committed Jan 27, 2023
1 parent f52de4d commit aa8403d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions frontend/components/Articles/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const route = useRoute()
let pagenum = 0
const isLoading = useState('isLoading', () => false)
const artlistData = useArtlist(await useFetchPostData())
console.log('0', artlistData.value)
const addArtListItem = () => {
if (useScrollBottom()) {
const timer = setTimeout(async () => {
Expand All @@ -20,15 +19,15 @@ const addArtListItem = () => {
}, 1000)
}
}
watch(route, (newRoute) => {
const type = newRoute.path.replace('/', '')
const sort = newRoute.query?.sort as string | undefined
watchEffect(() => {
const type = route.path.replace('/', '')
const sort = route.query?.sort as string | undefined
isLoading.value = true
useFetchPostData(type, sort).then((data) => {
artlistData.value = data
isLoading.value = false
})
}, { immediate: false, deep: true })
}, { flush: 'post' })
onMounted(() => {
const EmployeeWindow = window as any
EmployeeWindow.addEventListener('scroll', addArtListItem)
Expand Down

0 comments on commit aa8403d

Please sign in to comment.