mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-17 11:49:41 +08:00
fix: progress bar get stuck when navigating between routes (#18586)
This commit is contained in:
parent
2a9c6dacdc
commit
9d3cc84a3e
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, nextTick, onUpdated, ref, watch } from 'vue'
|
import { computed, nextTick, watch } from 'vue'
|
||||||
import nprogress from 'nprogress'
|
import nprogress from 'nprogress'
|
||||||
import { useData, useRoute } from 'vitepress'
|
import { useData, useRoute } from 'vitepress'
|
||||||
import { useSidebar } from '../composables/sidebar'
|
import { useSidebar } from '../composables/sidebar'
|
||||||
@ -16,23 +16,26 @@ const { hasSidebar } = useSidebar()
|
|||||||
|
|
||||||
const props = defineProps<{ isSidebarOpen: boolean }>()
|
const props = defineProps<{ isSidebarOpen: boolean }>()
|
||||||
|
|
||||||
const shouldUpdateProgress = ref(true)
|
let shouldUpdateProgress = true
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.isSidebarOpen,
|
() => props.isSidebarOpen,
|
||||||
(val) => {
|
(val) => {
|
||||||
// delay the flag update since watch is called before onUpdated
|
// delay the flag update since watch is called before onUpdated
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
shouldUpdateProgress.value = !val
|
shouldUpdateProgress = !val
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
watch(
|
||||||
onUpdated(() => {
|
() => route.path,
|
||||||
if (shouldUpdateProgress.value) {
|
() => {
|
||||||
nprogress.done()
|
if (shouldUpdateProgress) nprogress.done()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
flush: 'post',
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
Loading…
Reference in New Issue
Block a user