useNProgress.js 668 B

123456789101112131415161718192021222324252627282930313233
  1. import { nextTick } from 'vue'
  2. // import { useCssVar } from '@vueuse/core'
  3. import NProgress from 'nprogress'
  4. import 'nprogress/nprogress.css'
  5. // const primaryColor = useCssVar('--el-color-primary', document.documentElement)
  6. export const useNProgress = () => {
  7. NProgress.configure({ showSpinner: false })
  8. const initColor = async () => {
  9. await nextTick()
  10. const bar = document.getElementById('nprogress')?.getElementsByClassName('bar')[0]
  11. if (bar) {
  12. bar.style.background = 'primary'
  13. }
  14. }
  15. initColor()
  16. const start = () => {
  17. NProgress.start()
  18. }
  19. const done = () => {
  20. NProgress.done()
  21. }
  22. return {
  23. start,
  24. done
  25. }
  26. }