Skip to content

useNProgress

类别
导出体积
429 B
依赖包
@vueuse/integrations
上次更改
2 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
>
export interface UseNProgressReturn {
isLoading
:
WritableComputedRef
<boolean, boolean>
progress
:
Ref
<number | null | undefined>
start
: () =>
NProgress
done
: (
force
?: boolean) =>
NProgress
remove
: () => void
} /** * 响应式进度条。 * * @see https://vueuse.org/useNProgress */ export declare function
useNProgress
(
currentProgress
?:
MaybeRefOrGetter
<number | null | undefined>,
options
?:
UseNProgressOptions
,
): UseNProgressReturn

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
Antério Vieira
Vida Xie
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)