mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
chore(app): small refactor on $nuxt.hooks
This commit is contained in:
parent
520f48a9d2
commit
0346d6e88a
@ -2,7 +2,7 @@ import type { Plugin } from '@nuxt/app'
|
||||
|
||||
export default <Plugin> function progressbar ({ app }) {
|
||||
const { $nuxt } = app
|
||||
$nuxt.hooks.hook('app:mounted', () => {
|
||||
$nuxt.hook('app:mounted', () => {
|
||||
const el = document.createElement('div')
|
||||
el.id = 'nuxt-progress'
|
||||
document.body.appendChild(el)
|
||||
@ -16,7 +16,7 @@ export default <Plugin> function progressbar ({ app }) {
|
||||
const progress = 10000 / Math.floor(duration)
|
||||
let timeout
|
||||
let interval
|
||||
$nuxt.hooks.hook('page:start', () => {
|
||||
$nuxt.hook('page:start', () => {
|
||||
if (timeout) { return }
|
||||
timeout = setTimeout(() => {
|
||||
let width = 10
|
||||
@ -29,7 +29,7 @@ export default <Plugin> function progressbar ({ app }) {
|
||||
}, 100)
|
||||
}, 200)
|
||||
})
|
||||
$nuxt.hooks.hook('page:finish', () => {
|
||||
$nuxt.hook('page:finish', () => {
|
||||
timeout && clearTimeout(timeout)
|
||||
timeout = null
|
||||
interval && clearInterval(interval)
|
||||
|
@ -2,7 +2,7 @@
|
||||
<RouterView v-slot="{ Component }">
|
||||
<transition name="page" mode="out-in">
|
||||
<!-- <keep-alive> -->
|
||||
<Suspense @pending="$nuxt.hooks.callHook('page:start')" @resolve="$nuxt.hooks.callHook('page:finish')">
|
||||
<Suspense @pending="$nuxt.callHook('page:start')" @resolve="$nuxt.callHook('page:finish')">
|
||||
<component :is="Component" :key="$route.path" />
|
||||
</Suspense>
|
||||
<!-- <keep-alive -->
|
||||
|
Loading…
Reference in New Issue
Block a user