注意:网上搜索出来的都是教你在index.html里面或者在app.vue Mounte生命周期函数控制app和loading的显示和隐藏,这里会有一个问题,就是js渲染页面需要时间,一样会出现几秒钟白屏。mounted(包裹使用nextTick)执行回调div app的内容依然没有开始渲染。
正确的做法是给loading一个z-index:-1,绝对定位。当app有内容时覆盖loading,确保app的内容高度至少占一屏,不然会出现覆盖不全。
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
background-color: #ffffff;
background-color: #ffffff;
border: 10px solid #176af8;
border-bottom: #cccccc 10px solid;
-webkit-animation: load 1.1s infinite linear;
@-webkit-keyframes load {
transform: rotate(360deg);
<div id="appLoading" class="loading-model">
<div class="loading">div>
<script type="module" src="/src/main.ts">script>