提交 | 用户 | 时间
|
820397
|
1 |
import { useCssVar } from '@vueuse/core' |
H |
2 |
import type { NProgressOptions } from 'nprogress' |
|
3 |
import NProgress from 'nprogress' |
|
4 |
import 'nprogress/nprogress.css' |
|
5 |
|
|
6 |
const primaryColor = useCssVar('--el-color-primary', document.documentElement) |
|
7 |
|
|
8 |
export const useNProgress = () => { |
|
9 |
NProgress.configure({ showSpinner: false } as NProgressOptions) |
|
10 |
|
|
11 |
const initColor = async () => { |
|
12 |
await nextTick() |
|
13 |
const bar = document.getElementById('nprogress')?.getElementsByClassName('bar')[0] as ElRef |
|
14 |
if (bar) { |
|
15 |
bar.style.background = unref(primaryColor.value) |
|
16 |
} |
|
17 |
} |
|
18 |
|
|
19 |
initColor() |
|
20 |
|
|
21 |
const start = () => { |
|
22 |
NProgress.start() |
|
23 |
} |
|
24 |
|
|
25 |
const done = () => { |
|
26 |
NProgress.done() |
|
27 |
} |
|
28 |
|
|
29 |
return { |
|
30 |
start, |
|
31 |
done |
|
32 |
} |
|
33 |
} |