vue2组件懒加载(Vue Lazy Component )

1.介绍:是vue组件懒加载的预估插件组件。支持组件组件延时加载, 加载真实组件前展示骨架组件,提高用户体验,真实组件代码分包异步加载

复制代码
// 安装 

npm install @xunlei/vue-lazy-component

// 使用方式一

// main.js文件中全局注册使用

import VueLazyComponent from '@xunlei/vue-lazy-component'

Vue.use(VueLazyComponent)


// 使用方式二

// 在组件中实现局部注册组件


import { component as VueLazyComponent } from '@xunlei/vue-lazy-component'

export default {

  components: {
    'vue-lazy-component': VueLazyComponent
  }
}
复制代码

2.在组件中使用懒加载组件

复制代码
<!--

    需要懒加载的组件将其包裹在vue-lazy-component中

    slot值为 skeleton 指的是在懒加载过程中显示的加载状态组件
-->

<vue-lazy-component :timeout="5000" tagName="div">

      <child1 slot="skeleton" />

      <child2 />

      <child3 />

      <child4 />

      <child5 />

</vue-lazy-component>
复制代码

3.参数以及事件的介绍

 

 

 

posted @   不再犯错  阅读(774)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2017-02-15 30行js让你的rem弹性布局适配所有分辨率(含竖屏适配)
2017-02-15 js适配根字体大小
点击右上角即可分享
微信分享提示