在使用乾坤微前端框架中,遇见图片资源路径存在访问问题,在不搭CDN的情况下,使用base64方式将图片资源打入代码。这样会导致包体积过大,加载时间长;
所以加了一个loading效果;
1.在index.html入口增加 loading;

<!DOCTYPE html>
<html lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="icon" href="<%= BASE_URL %>favicon.ico">
  <!-- <script type="text/javascript" src="./config.js"></script> -->
  <title>
    <%= htmlWebpackPlugin.options.title %>
  </title>
</head>
<style media="screen" type="text/css">
  /* #app-cockpit-loading { width: 100%; height: 100%; }
  #app-cockpit-loading span {
       position: absolute;
       display: block;
       font-size: 50px;
       line-height: 50px;
       top: 50%;
       left: 50%;
       width: 200px;
       height: 100px;
       -webkit-transform: translateY(-50%)  translateX(-50%);
       transform: translateY(-50%)  translateX(-50%);
   } */

  #app-cockpit-loading {
    width: 120px;
    height: 40px;
    position: absolute;
    font-size: 50px;
    line-height: 50px;
    top: 50%;
    left: 50%;
    transform: translateY(-50%) translateX(-50%);
  }

  #app-cockpit-loading span {
    display: inline-block;
    width: 8px;
    height: 100%;
    border-radius: 4px;
    background: lightgreen;
    -webkit-animation: load 1s ease infinite;
  }

  @-webkit-keyframes load {

    0%,
    100% {
      height: 40px;
      background: lightgreen;
    }

    50% {
      height: 70px;
      margin: -15px 0;
      background: lightblue;
    }
  }

  #app-cockpit-loading span:nth-child(2) {
    -webkit-animation-delay: 0.2s;
  }

  #app-cockpit-loading span:nth-child(3) {
    -webkit-animation-delay: 0.4s;
  }

  #app-cockpit-loading span:nth-child(4) {
    -webkit-animation-delay: 0.6s;
  }

  #app-cockpit-loading span:nth-child(5) {
    -webkit-animation-delay: 0.8s;
  }
  
</style>

<body>
  <noscript>
    <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
        Please enable it to continue.</strong>
  </noscript>
  <div id="app-cockpit-loading">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
  </div>
  <div id="app"></div>
  <!-- built files will be auto injected -->
</body>

</html>

2.在app.vue mounted()中执行
document.getElementById('app-cockpit-loading').remove();

Logo

前往低代码交流专区

更多推荐