主题
useNProgress
针对 nprogress 的响应式封装。
🌐 Reactive wrapper for nprogress.
示例
Available in the @vueuse/integrations add-on.安装
🌐 Install
bash
npm i nprogress@^0用法
🌐 Usage
ts
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.
ts
import { useNProgress } from '@vueuse/integrations/useNProgress'
const { progress } = useNProgress(0.5)
function done() {
progress.value = 1.0
}要更改进度百分比,请设置
progress.value = n,其中 n 是介于 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.
你可以通过将一个对象作为第二个参数传递来配置它。
🌐 You can configure it by passing an object as a second parameter.
ts
import { useNProgress } from '@vueuse/integrations/useNProgress'
useNProgress(null, {
minimum: 0.1,
// ...
})