Logintoyouraccount

Iamasync!'})}))defineAsyncComponent可以接受一个返回的Promise工厂功能。Promise的resolve回调应该在服务端返回组件定义后调用。您还可以调用reject(reason)来指示加载失败。defineAsyncComponent可以从vue导入并使用:import{defineAsyncComponent}from"vue"//简单用法constLoginPopup=defineAsyncComponent(()=>import("./components/LoginPopup.vue"))这是最简单的defineAsyncComponent方法,对于高级用法,defineAsyncComponent可以接受一个对象:constAsyncPopup=defineAsyncComponent({loader:()=>import("./LoginPopup.vue"),//加载异步组件时要使用的组件loadingComponent:LoadingComponent,//加载失败时使用的组件errorComponent:ErrorComponent,//显示loadingComponent之前的延迟|默认值:200(毫秒)delay:1000,//如果提供超时,加载组件的时间超过设置值,会显示错误组件//Defaultvalue:Infinity(即永不超时,单位ms)timeout:3000})基础介绍完了,接下来,我们来打个例子。使用defineAsyncComponent异步加载Popup组件在本例中,我们将使用通过单击按钮触发的登录弹出窗口。我们不需要我们的应用程序在每次加载时都加载此组件,因为只有在用户执行特定操作时才需要它。下面是登录组的实现://LoginPopup.vueLogintoyouraccount
LoadedAPI:{{article}}
Loading...