Skip to content

useNProgress

类别
导出体积
531 B
依赖包
@vueuse/integrations
上次更改
7 months ago

nprogress 的响应式封装。

示例

Click to change progress status
Available in the @vueuse/integrations add-on.

安装

bash
npm i nprogress@^0

使用方法

ts
import { 
useNProgress
} from '@vueuse/integrations/useNProgress'
const {
isLoading
} =
useNProgress
()
function
toggle
() {
isLoading
.
value
= !
isLoading
.
value
}

传递进度百分比

你可以传递一个百分比来指示进度条应该从哪里开始。

ts
import { 
useNProgress
} from '@vueuse/integrations/useNProgress'
const {
progress
} =
useNProgress
(0.5)
function
done
() {
progress
.
value
= 1.0
}

要更改进度百分比,请设置 progress.value = n,其中 n 是介于 0 到 1 之间的数字。

自定义

只需编辑 nprogress.css 以满足你的喜好。提示:你可能只想查找和替换 #29d 的出现。

你可以通过将对象作为第二个参数传递来配置它。

ts
import { 
useNProgress
} from '@vueuse/integrations/useNProgress'
useNProgress
(null, {
minimum
: 0.1,
// ... })

类型声明

ts
export type 
UseNProgressOptions
=
Partial
<
NProgressOptions
>
/** * 响应式进度条。 * * @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
>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
Antério Vieira
SerKo
IlyaL
Robin
IlyaL
Robin
Robert Soriano
Doctorwu
丶远方
Agénor Debriat
webfansplz
Curt Grimes
Jelf
Michael Hüneburg
Alex Kozack

更新日志

7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)