主题
使用 NProgress
¥useNProgress
nprogress
的反应式封装。
¥Reactive wrapper for nprogress
.
示例
Click to change progress status
安装
¥Install
bash
npm i nprogress@^0
用法
¥Usage
js
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.
js
import { useNProgress } from '@vueuse/integrations/useNProgress'
const { progress } = useNProgress(0.5)
function done() {
progress.value = 1.0
}
要更改进度百分比,请设置
progress.value = n
,其中 n 是 0..1 之间的数字。¥To change the progress percentage, set
progress.value = n
, where n is a number between 0..1.
定制化
¥Customization
只需根据你的喜好编辑 nprogress.css 即可。提示:你可能只想查找并替换 #29d 的出现。
¥Just edit nprogress.css to your liking. Tip: you probably only want to find and replace occurrences of #29d.
你可以通过传递一个对象作为第二个参数来对其进行 configure 处理。
¥You can configure it by passing an object as a second parameter.
js
import { useNProgress } from '@vueuse/integrations/useNProgress'
useNProgress(null, {
minimum: 0.1,
// ...
})
类型声明
typescript
export type UseNProgressOptions = Partial<NProgressOptions>
/**
* Reactive progress bar.
*
* @see https://vueuse.org/useNProgress
*/
export declare function useNProgress(
currentProgress?: MaybeRefOrGetter<number | null | undefined>,
options?: UseNProgressOptions,
): {
isLoading: WritableComputedRef<boolean, boolean>
progress: Ref<number | null | undefined, number | null | undefined>
start: () => nprogress.NProgress
done: (force?: boolean) => nprogress.NProgress
remove: () => void
}
export type UseNProgressReturn = ReturnType<typeof useNProgress>