nprogress.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import NProgress from 'nprogress'
  2. // 创建style标签并添加样式
  3. const styleContent = `
  4. #nprogress {
  5. pointer-events: none;
  6. }
  7. #nprogress .bar {
  8. background: #29d;
  9. position: fixed;
  10. z-index: 1031;
  11. top: 0;
  12. left: 0;
  13. width: 100%;
  14. height: 2px;
  15. }
  16. #nprogress .peg {
  17. display: block;
  18. position: absolute;
  19. right: 0px;
  20. width: 100px;
  21. height: 100%;
  22. box-shadow: 0 0 10px #29d, 0 0 5px #29d;
  23. opacity: 1.0;
  24. transform: rotate(3deg) translate(0px, -4px);
  25. }
  26. #nprogress .spinner {
  27. display: none;
  28. position: fixed;
  29. z-index: 1031;
  30. top: 15px;
  31. right: 15px;
  32. }
  33. #nprogress .spinner-icon {
  34. width: 18px;
  35. height: 18px;
  36. box-sizing: border-box;
  37. border: solid 2px transparent;
  38. border-top-color: #29d;
  39. border-left-color: #29d;
  40. border-radius: 50%;
  41. animation: nprogress-spinner 400ms linear infinite;
  42. }
  43. @keyframes nprogress-spinner {
  44. 0% { transform: rotate(0deg); }
  45. 100% { transform: rotate(360deg); }
  46. }
  47. `
  48. // 在运行时动态添加样式
  49. const style = document.createElement('style')
  50. style.type = 'text/css'
  51. style.innerHTML = styleContent
  52. document.head.appendChild(style)
  53. // 配置 NProgress
  54. NProgress.configure({
  55. showSpinner: false,
  56. minimum: 0.3,
  57. easing: 'ease',
  58. speed: 500,
  59. trickle: true,
  60. trickleSpeed: 200,
  61. })
  62. export default NProgress