vue3-异步组件的使用
2024-10-20 01:35:00
我们通常会在实际开发中,将项目进行分包处理,以此加快项目的速度
即使用异步组件
//异步组件,分包处理
import {defineAsyncComponent} from "vue";
import Loading from "@/11_异步组件的使用/Loading";
//1.
const AsyncCategory = defineAsyncComponent(() => {
import("./AsyncCategory")
}) //2.
// const AsyncCategory = defineAsyncComponent({
// loader:()=>import("./AsyncCategory"),
// //loader没下载下来的时候,用loadingComponent来占位
// loadingComponent:Loading,
// errorComponent:Error,
// //delay:在显示loadingComponent组件之前等待多长时间
// delay:2000,
// /*
// * err是错误信息
// * retry:是一个函数,调用retry尝试重新加载
// * attempts:调用retry的次数
fail:一个函数,失败后直接退出
// * */
//
onError(error, retry, fail, attempts) {
if (error.message.match(/fetch/) && attempts <= 3) {
// 请求发生错误时重试,最多可尝试 3 次
retry()
} else {
// 注意,retry/fail 就像 promise 的 resolve/reject 一样:
// 必须调用其中一个才能继续错误处理。
fail()
}
}
//
//
//
// })
export default {
name: "App",
components: {
Loading,
Home,
AsyncCategory
}
}
最新文章
- Linux 命令——简约汇总
- 监听grid行点击事件
- Javascript的逻辑判断和循环的知识点
- css兼容问题集合
- TextArea限制输入长度
- leetcode解决问题的方法||Integer to Roman问题
- Protel99se轻松入门:一些高级设置和常用技巧
- android 中判断WiFi是否可用的可靠方法 ,android 是否联网
- 进军VR虚拟现实-先来全景智慧城市-有梦想的互联网创业者
- 有序链表--Java实现
- 中文版microbit:TurnipBit显示动态滚动字符教程实例
- partition分区
- selenium+PhantomJS小案例—爬豆瓣网所有电影代码python
- ThinkPHP数据库操作相关
- response.sendRedirect(url)与request.getRequestDispatcher(url).forward(request,response)的区别
- 深入JVM对象引用
- http://www.bugku.com:Bugku——备份是个好习惯(http://120.24.86.145:8002/web16/)
- 项目经验总结-first
- 盘点Linux内核源码中使用宏定义的若干技巧(1)
- centos7上docker安装和使用教程
热门文章
- vue 中 使用 element-ui 发送请求前 校验全部表单,报警告: [Element Warn][Form]model is required for validate to work!
- DHCP原理与LINUX下的配置
- Net6 DI源码分析Part3 CallSiteRuntimeResolver,CallSiteVisitor
- python篇第10天【For 循环语句】
- PL/SQL批量执行SQL脚本文件
- Solution -「LOCAL」过河
- java Doc的生成方式
- Python中类的定制
- [VIP] openstack环境配置VIP
- 让你的Linux像黑客帝国的画面一样炫酷