chore(app): small refactor on $nuxt.hooks

This commit is contained in:
Sébastien Chopin 2021-05-06 23:25:48 +02:00
parent 520f48a9d2
commit 0346d6e88a
2 changed files with 4 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import type { Plugin } from '@nuxt/app'
export default <Plugin> function progressbar ({ app }) { export default <Plugin> function progressbar ({ app }) {
const { $nuxt } = app const { $nuxt } = app
$nuxt.hooks.hook('app:mounted', () => { $nuxt.hook('app:mounted', () => {
const el = document.createElement('div') const el = document.createElement('div')
el.id = 'nuxt-progress' el.id = 'nuxt-progress'
document.body.appendChild(el) document.body.appendChild(el)
@ -16,7 +16,7 @@ export default <Plugin> function progressbar ({ app }) {
const progress = 10000 / Math.floor(duration) const progress = 10000 / Math.floor(duration)
let timeout let timeout
let interval let interval
$nuxt.hooks.hook('page:start', () => { $nuxt.hook('page:start', () => {
if (timeout) { return } if (timeout) { return }
timeout = setTimeout(() => { timeout = setTimeout(() => {
let width = 10 let width = 10
@ -29,7 +29,7 @@ export default <Plugin> function progressbar ({ app }) {
}, 100) }, 100)
}, 200) }, 200)
}) })
$nuxt.hooks.hook('page:finish', () => { $nuxt.hook('page:finish', () => {
timeout && clearTimeout(timeout) timeout && clearTimeout(timeout)
timeout = null timeout = null
interval && clearInterval(interval) interval && clearInterval(interval)

View File

@ -2,7 +2,7 @@
<RouterView v-slot="{ Component }"> <RouterView v-slot="{ Component }">
<transition name="page" mode="out-in"> <transition name="page" mode="out-in">
<!-- <keep-alive> --> <!-- <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" /> <component :is="Component" :key="$route.path" />
</Suspense> </Suspense>
<!-- <keep-alive --> <!-- <keep-alive -->