useNProgress
Reactive wrapper for nprogress
Demo
Click to change progress status
Usage
import { useNProgress } from '@vueuse/integrations/useNProgress'
const { isLoading } = useNProgress()
function toggle() {
isLoading.value = !isLoading.value
}
import { useNProgress } from '@vueuse/integrations/useNProgress'
const { isLoading } = useNProgress()
function toggle() {
isLoading.value = !isLoading.value
}
Passing a progress percentage
You can pass a percentage to indicate where the bar should start from.
import { useNProgress } from '@vueuse/integrations/useNProgress'
const { progress } = useNProgress(0.5)
function done() {
progress.value = 1.0
}
import { useNProgress } from '@vueuse/integrations/useNProgress'
const { progress } = useNProgress(0.5)
function done() {
progress.value = 1.0
}
To change the progress percentage, set
progress.value = n
, where n is a number between 0..1.
Customization
Just edit nprogress.css to your liking. Tip: you probably only want to find and replace occurrences of #29d.
You can configure it by passing an object as a second parameter.
import { useNProgress } from '@vueuse/integrations/useNProgress'
useNProgress(null, {
minimum: 0.1,
// ...
})
import { useNProgress } from '@vueuse/integrations/useNProgress'
useNProgress(null, {
minimum: 0.1,
// ...
})
Type Declarations
/**
* Reactive progress bar.
*
* @see https://vueuse.org/useNProgress
* @param currentProgress
* @param options
*/
export declare function useNProgress(
currentProgress?: MaybeRef<number | null | undefined>,
options?: NProgressOptions | undefined
): {
isLoading: WritableComputedRef<boolean>
progress: Ref<number | null | undefined>
start: () => nprogress.NProgress
done: (force?: boolean | undefined) => nprogress.NProgress
remove: () => void
}
/**
* Reactive progress bar.
*
* @see https://vueuse.org/useNProgress
* @param currentProgress
* @param options
*/
export declare function useNProgress(
currentProgress?: MaybeRef<number | null | undefined>,
options?: NProgressOptions | undefined
): {
isLoading: WritableComputedRef<boolean>
progress: Ref<number | null | undefined>
start: () => nprogress.NProgress
done: (force?: boolean | undefined) => nprogress.NProgress
remove: () => void
}
Source
Contributors
Anthony Fu
Antério Vieira
Alex Kozack
Changelog
v6.0.0-beta.2
on 8/9/2021ff21b
- feat: use tryOnScopeDispose instead of tryOnUnmounted