<div class="skeleton-swiper-item item-one"></div>
<div class="skeleton-swiper-item item-two"></div>
</div>
</div>
</template>
<style>
html,body,div{
margin:0;
padding:0;
}
.skeleton {
height: 100%;
overflow: hidden;
box-sizing: border-box;
background: #fff;
}
.skeleton-nav {
height: 54px;
background: #eee;
margin-bottom: 20px;
}
.skeleton-swiper {
min-height:600px;
max-width:1280px;
margin:0 auto;
}
.skeleton-swiper-item{
min-height: 600px;
height:100%;
background:#eee;
border-radius:5px;
}
.item-one{
width:20%;
float:left;
}
.item-two{
width:78%;
float:right;
}
</style>
接下来,在/src目录再新建一个skeleton.entry.js入口文件:
import Vue from 'vue';
import Skeleton from './Skeleton.vue';export default new Vue({
components: {
Skeleton,
},
template: '<skeleton />',
});
在完成了骨架屏的准备之后,我们需要一个关键插件vue-server-renderer。该插件本用于服务端渲染,但是在这里,我们主要利用它能够把.vue文件处理成html和css字符串的功能,来完成骨架屏的注入。
骨架屏注入
首先在public文件夹下新建一个template.html文件,并且其代码和index.html文件代码相同,但是需要在div#app中添加
<!--vue-ssr-outlet--> 占位符:
<!DOCTYPE html>
<html lang="en">
<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="./favicon.ico" rel="external nofollow" >
<title>医生工作台</title>
</head>
<body>
<noscript>
<strong>We're sorry but yz_doctors doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"><!--vue-ssr-outlet--></div>
<!-- built files will be auto injected -->
</body>
</html>然后,我们还需要在根目录新建一个webpack.skeleton.conf.js文件,以专门用来进行骨架屏的构建。
const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
module.exports = {
target: 'node',
entry: {










