为什么要使用
数据都都是ajax请求渲染来的 然后它可能请求的慢就会一片白 这不好 所以就要使用骨架屏了 站位 像这样
创建个组件
<template><divclass="xtx-skeleton shan":style="{width:'100px',height:'50px'}"><!--1 盒子--><divclass="block":style="{backgroundColor:'black'}"></div><!--2 闪效果 xtx-skeleton 伪元素---></div></template><script>exportdefault{ name:'Skeleton'}</script><style scoped lang="less">.xtx-skeleton{ display: inline-block; position: relative; overflow: hidden; vertical-align: middle;.block{ width:100%; height:100%; border-radius:2px;}}.shan{&::after{ content:""; position: absolute; animation: shan1.5s ease0s infinite; top:0; width:50%; height:100%; background: linear-gradient( to left,rgba(255,255,255,0)0,rgba(255,255,255,0.3)50%,rgba(255,255,255,0)100%); transform:skewX(-45deg);}} @keyframes shan{0%{ left:-100%;}100%{ left:120%;}}</style>
样子是有过度效果的 闪闪的
这样写都是固定大小 要修改一下
<template><divclass="xtx-skeleton shan":style="{width:width,height:height}"><!--1 盒子--><divclass="block":style="{backgroundColor:background}"></div><!--2 闪效果 xtx-skeleton 伪元素---></div></template><script>exportdefault{ name:'XtxSkeleton', props:{ width:{default:'30px', type: String}, height:{default:'30px', type: String}, background:{default:'black', type: String}}}</script>
在使用的时候 传入需要的大小就行了
<XtxSkeletonwidth="100px"height="100px"background="blue"/>
全局组成
import XtxSkeletonfrom'@/components/XtxSkeleton.vue'exportdefault{install(app){ app.component(XtxSkeleton.name, XtxSkeleton)}}
真实使用
<ulclass="menu"v-if="$store.state.category.list.length > 0"><li:class="{active:item.id===id}"v-for="item in categoryList":key="item.id"@mouseenter="id = item.id"><RouterLinkto="/"> {{ item.name }}</RouterLink><templatev-if="item.children"><RouterLinkv-for="sub in item.children.slice(0, 2)":key="sub.id"to="/"> {{ sub.name }}</RouterLink></template></li></ul><ulclass="menu"v-else><liv-for="(item,idx) in 10":key="idx"><XtxSkeletonstyle="margin-right:10px"width="50px"height="25px"background="#3d3c3b"></XtxSkeleton><XtxSkeletonstyle="margin-right:10px"width="50px"height="25px"background="#3d3c3b"></XtxSkeleton><XtxSkeletonstyle="margin-right:10px"width="50px"height="25px"background="#3d3c3b"></XtxSkeleton></li></ul>
热门文章
- 2月13日免费VPN节点 | 18.6M/S|2025年Clash/Shadowrocket/V2ray/SSR免费订阅链接地址
- 动物疫苗注射注意事项有哪些内容(动物疫苗注射工作注意事项)
- 宠物领养市场调研报告(宠物寄养市场调查)
- 动物疫苗龙头企业名单公示最新(动物疫苗龙头公司)
- 三国杀武将盘点(三国杀武将大合集2021)
- 国货猫粮排行榜前十名(2021年国产猫粮推荐与测评)
- 做狗粮的机器多少钱一台(狗粮加工厂投资多少钱)
- 动物疫苗对人有害处吗知乎(动物疫苗有没有毒)
- 济南领养狗狗贴吧 济南领养狗狗贴吧论坛
- 2月11日免费VPN节点 | 22M/S|2025年SSR/V2ray/Shadowrocket/Clash免费订阅链接地址
归纳
-
36 2025-02