vue之vue-content-loader内容加载器使用

小灰灰 2022-12-10 15:00 267阅读 0赞

一、前言

在打开一个页面时候,如果遇到界面内容多或者接口请求慢导致加载速度慢时,这时候会导致页面出现较长时间的空白页面,影响用户的体验感,vue-content-loader正是解决该场景问题的一个组件。

二、特性

1、完全可定制:你可以改变颜色,速度和大小
2、创建自己的加载:使用在线工具轻松创建你的自定义加载
3、你现在就可以使用它:已经有很多预设了
4、性能

  • Tree-shakable and highly optimized bundle
  • 纯SVG, 因此它不需要任何 javascript, canvas,等
  • 纯功能部件

三、使用

1.引入

当前版本0.2.3

  1. npm i vue-content-loader

npm组件库地址:https://www.npmjs.com/package/vue-content-loader

1.使用
  1. <template>
  2. <content-loader></content-loader>
  3. </template>
  4. <script>
  5. import { ContentLoader } from 'vue-content-loader'
  6. export default {
  7. components: {
  8. ContentLoader
  9. }
  10. }
  11. </script>
  12. import {
  13. ContentLoader,
  14. FacebookLoader,
  15. CodeLoader,
  16. BulletListLoader,
  17. InstagramLoader,
  18. ListLoader
  19. } from 'vue-content-loader'
(1) FacebookLoader

效果如下:
在这里插入图片描述

(2) CodeLoader

效果如下:
在这里插入图片描述

(3) BulletListLoader

效果如下:
在这里插入图片描述

(3) InstagramLoader

效果如下:
在这里插入图片描述

(4) ListLoader

效果如下:
在这里插入图片描述

(5) ContentLoader

ContentLoader是一个元加载程序,而其他加载程序只是它的高阶组件。默认情况下,ContentLoader只显示一个简单的矩形,同时你也可以自定义自己的加载器

默认情况下效果:

  1. <content-loader></content-loader>

在这里插入图片描述
可以自定义自己的加载布局,比如一个移动端的首页界面如下:

  1. <content-loader
  2. :width="414"
  3. :height="836"
  4. :speed="1"
  5. primaryColor="#f3f3f3"
  6. secondaryColor="#ecebeb"
  7. >
  8. <rect x="6" y="10" rx="5" ry="5" width="100" height="20" />
  9. <rect x="11" y="54" rx="0" ry="0" width="384" height="110" />
  10. <rect x="7" y="176" rx="0" ry="0" width="400" height="125" />
  11. <rect x="320" y="235" rx="0" ry="0" width="24" height="0" />
  12. <rect x="123" y="17" rx="0" ry="0" width="274" height="20" />
  13. <circle cx="36" cy="329" r="15" />
  14. <rect x="13" y="352" rx="0" ry="0" width="51" height="5" />
  15. <circle cx="124" cy="329" r="15" />
  16. <rect x="101" y="352" rx="0" ry="0" width="51" height="5" />
  17. <circle cx="211" cy="329" r="15" />
  18. <rect x="184" y="352" rx="0" ry="0" width="51" height="5" />
  19. <circle cx="289" cy="329" r="15" />
  20. <rect x="263" y="352" rx="0" ry="0" width="51" height="5" />
  21. <circle cx="371" cy="329" r="15" />
  22. <rect x="345" y="352" rx="0" ry="0" width="51" height="5" />
  23. <circle cx="37" cy="394" r="15" />
  24. <rect x="11" y="423" rx="0" ry="0" width="51" height="5" />
  25. <circle cx="126" cy="394" r="15" />
  26. <rect x="101" y="423" rx="0" ry="0" width="51" height="5" />
  27. <circle cx="213" cy="394" r="15" />
  28. <rect x="195" y="424" rx="0" ry="0" width="52" height="0" />
  29. <rect x="187" y="423" rx="0" ry="0" width="51" height="5" />
  30. <circle cx="288" cy="394" r="15" />
  31. <rect x="263" y="423" rx="0" ry="0" width="51" height="5" />
  32. <circle cx="371" cy="394" r="15" />
  33. <rect x="13" y="443" rx="0" ry="0" width="357" height="76" />
  34. <rect x="56" y="537" rx="0" ry="0" width="103" height="60" />
  35. <rect x="224" y="537" rx="0" ry="0" width="103" height="60" />
  36. <rect x="59" y="606" rx="0" ry="0" width="100" height="5" />
  37. <rect x="59" y="616" rx="0" ry="0" width="100" height="5" />
  38. <rect x="59" y="627" rx="0" ry="0" width="100" height="5" />
  39. <rect x="225" y="607" rx="0" ry="0" width="100" height="5" />
  40. <rect x="227" y="618" rx="0" ry="0" width="100" height="5" />
  41. <rect x="227" y="627" rx="0" ry="0" width="100" height="5" />
  42. </content-loader>

在这里插入图片描述

2.相关api













































































Prop Type Default Description
width number 400
height number 130
speed number 2
preserveAspectRatio string ‘xMidYMid meet’
primaryColor string ‘#f9f9f9’
secondaryColor string ‘#ecebeb’
uniqueKey string randomId() Unique ID, you need to make it consistent for SSR
animate boolean true
baseUrl string empty string Required if you’re using <base url=”/“ /> in your <head />. Defaults to an empty string. This prop is common used as: <content-loader :base-url=”$route.fullPath” /> which will fill the SVG attribute with the relative path. Related #14.
primaryOpacity number 1 Background opacity (0 = transparent, 1 = opaque) used to solve an issue in Safari
secondaryOpacity number 1 Background opacity (0 = transparent, 1 = opaque) used to solve an issue in Safari

发表评论

表情:
评论列表 (有 0 条评论,267人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ——类与类

    虚拟机设计团队把类加载阶段中的“通过一个类的全限定名来获取描述此类的二进制字节流”这个动作放到Java虚拟机外部去实现,以便让应用程序自己决定如何去获取所需要的类。实现这个动作

    相关 JVM类过程

    我们知道在jvm中是通过各类形形色色的类加载器对class文件进行加载后才能进行使用的,而且jvm中能提供动态加载的特性也全是依靠类加载的机制,它已经成为了Java体系中