温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用vue-cli怎么构建一个骨架屏

发布时间:2021-04-12 17:35:01 阅读:202 作者:Leah 栏目:web开发
Vue开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

使用vue-cli怎么构建一个骨架屏?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

安装 vue-skeleton-webpack-plugin

npm install vue-skeleton-webpack-plugin

创建文件 skeleton.js和skeleton.vue

skeleton.js

import Vue from 'vue'

import Skeleton from './Skeleton.vue'


export default new Vue({

components: {

Skeleton

},

template'<skeleton />'

})

skeleton.vue

我的skeleton.vue不知为何<style>标签写在外部没有加载进去,故写到<template>内

样式和模板可以自己修改

<template>

<div class="skeleton-wrapper">
<style>
.skeleton {
padding10px;
}

.skeleton .skeleton-head,
.skeleton .skeleton-title,
.skeleton .skeleton-content-bottom,
.skeleton .skeleton-content {
backgroundrgba(194207214,.5);
background-imagelinear-gradient(90deg,rgba(2552552550.1525%, transparent 25%);
background-size20rem 20rem;
animation: skeleton-stripes 1s linear infinite;
margin0 auto 30px;
text-align: center;
color: darkgray;
}

.skeleton-head {
width100px;
height60px;
float: left;
}

.skeleton-body {
margin-left110px;
}

.skeleton-title {
width90%;
height60px;
line-height60px;
}

.skeleton-content {
width60%;
height40px;
backgroundrgba(194207214,.3)!important;
}
.skeleton-content-bottom {
width40%;
height40px;
margin0 auto 30px 20%!important;
backgroundrgba(194207214,.3)!important;
}
@keyframes skeleton-stripes {
from {
background-position0 0 ;
}
to {
background-position20rem 0;
}
}

</style>
<header class="skeleton-header"></header>
<section class="skeleton-block">
<div class="skeleton">
<div class="skeleton-head"></div>
<div class="skeleton-body">
<div class="skeleton-title">加载中</div>
<div class="skeleton-content"></div>
<div class="skeleton-content-bottom"></div>
<div class="skeleton-content"></div>
<div class="skeleton-content-bottom"></div>
<div class="skeleton-content"></div>
<div class="skeleton-content-bottom"></div>
<div class="skeleton-content"></div>
<div class="skeleton-content-bottom"></div>
<div class="skeleton-content"></div>
</div>
</div>
</section>
</div>
</template>

<script>
export default {
name'skeleton'
}
</script>

在build 目录下创建 webpack.skeleton.conf.js

'use strict';

const path require('path')
const merge require('webpack-merge')
const baseWebpackConfig require('./webpack.base.conf')
const nodeExternals require('webpack-node-externals')

function resolve(dir{
return path.join(__dirname, dir)
}

module.exports = merge(baseWebpackConfig, {
target'node',
devtoolfalse,
entry: {
//指向自己的skeleton.js路径
appresolve('../src/renderer/skeleton/skeleton.js')
},
output: Object.assign({}, baseWebpackConfig.output, {
libraryTarget'commonjs2'
}),
externalsnodeExternals({
whitelist: /\.css$/
}),
plugins: []
})

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×