首屏加载时间过长的影响,采用“骨架屏”的方式去提升用户体验。
骨架屏封装全局组件 install注入
- 骨架屏组件 src/components/library/skeleton.vue
<script setup lang="ts" name="skeleton">
defineProps({
bg: {
//背景颜色
type: String,
default: '#efefef',
},
width: {
//宽度
type: Number,
},
height: {
//高度
type: Number,
},
animated: {
// 动画
type: Boolean,
default: false,
},
fade: {
// 淡入淡出
type: Boolean,
default: false,
},
})
</script>
<template>
<div
class="skeleton"
:style="{ width: width + 'px', height: height + 'px' }"
:class="{ shan: animated, fade }"
>
<!-- 1 盒子-->
<div class="block" :style="{ backgroundColor: bg }"></div>
<