当前位置:   article > 正文

vue全局Loading_vue 全局loading

vue 全局loading

创建loading.js

  1. import { Loading } from 'element-ui'
  2. let loadingCount = 0
  3. let loading
  4. const startLoading = (text) => {
  5. loading = Loading.service({
  6. lock: true,
  7. text: text || '拼命加载中...', // 可以自定义文字
  8. spinner: 'iconfont icon-loading user-loading', // 自定义加载图标类名
  9. background: 'rgba(0, 0, 0, 0.7)'// 遮罩层背景色
  10. })
  11. }
  12. const endLoading = () => {
  13. loading.close()
  14. }
  15. function showLoading(text) {
  16. if (loadingCount === 0) {
  17. startLoading(text)
  18. }
  19. loadingCount += 1
  20. }
  21. function hideLoading() {
  22. if (loadingCount <= 0) {
  23. return
  24. }
  25. loadingCount -= 1
  26. if (loadingCount === 0) {
  27. endLoading()
  28. }
  29. }
  30. export default {
  31. hideLoading,
  32. showLoading
  33. }

user-loading.scss

  1. // 全局 loading
  2. @keyframes rotating {
  3. from {
  4. transform: rotate(0);
  5. }
  6. to {
  7. transform: rotate(360deg);
  8. }
  9. }
  10. .el-loading-mask > .el-loading-spinner>.user-loading{
  11. animation: rotating 2s linear infinite ;
  12. display: inline-block;
  13. font-size: 40px !important;
  14. }

main.js 引入

  1. // 全局loading
  2. import '@/styles/user-loading.scss'
  3. import useLoading from './utils/loading'
  4. Vue.prototype.$useLoading = useLoading

页面使用

  1. this.$useLoading.showLoading('正在为您翻译,请稍后...')
  2. this.$useLoading.hideLoading()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/218882?site
推荐阅读
相关标签
  

闽ICP备14008679号