毫无疑问,Suspense 功能会带来更干净的代码库,但尽管它很整洁,但它却很难测试。具体来说,它还没有很好的记录。
VUE CLI 生成的常规应用程序
我按照以下建议使用了 Suspense 组件:
<RouterView name="default" v-slot="{ Component, route }">
<transition :name="route.meta.transition" mode="out-in" :duration="300" :key="route.path">
<Suspense >
<template #default>
<component :is="Component" :key="route.path"/>
</template>
<template #fallback>
<div class="top-0 right-0 h-screen w-screen z-50 flex justify-center items-center">
<div class="animate-spin rounded-full h-32 w-32 border-t-2 border-b-2 border-yellow-700"></div>
</div>
</template>
</Suspense>
</transition>
</RouterView>
Run Code Online (Sandbox Code Playgroud)
// here is the gotcha, if ever I removed async from setup the test runs well otherwise it always returns empty vm.
async …Run Code Online (Sandbox Code Playgroud)