Suspense组件
等待异步组件时额外渲染一些内容,让应用有更好的用户体验
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <template> <div class="app"> <h3>我是App组件(祖)</h3> <Suspense> <template v-slot:default> <Child/> </template> <template v-slot:fallback> <h3>稍等,加载中……</h3> </template> </Suspense> </div> </template> <script> import {defineAsyncComponent} from "vue"; const Child=defineAsyncComponent(()=>import('./components/Child.vue')) //异步引入 export default { name: 'App', setup(){ }, components:{Child} } </script> <style> .app{ background-color: gray; padding:10px; } </style>
|