当前位置:网站首页>suspense组件和异步组件
suspense组件和异步组件
2022-06-24 19:27:00 【aliven1】
等待异步组件时渲染一些额外内容,让应用有更好的用户体验
使用步骤:
异步引入组件,使用defineAsyncComponent定义异步组件
import { defineAsyncComponent} from 'vue' const Child = defineAsyncComponent(()=>import('./components/Child.vue'))
使用
Suspense
包裹组件,并配置好default
与fallback
<template> <div class="app"> <h3>我是App组件</h3> <Suspense> <template v-slot:default> <Child/> </template> <template v-slot:fallback> <h3>加载中.....</h3> </template> </Suspense> </div> </template>
- 异步组件child中setup可以定义为异步函数,使用异步组件需要用Suspense包裹
<template>
<div class="child">
<h3>我是Child组件</h3>
{
{
sum}}
</div>
</template>
<script>
import {
ref} from 'vue'
export default {
name:'Child',
async setup(){
let sum = ref(0)
let p = new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve({
sum})
},1000)
})
return await p
}
}
</script>
边栏推荐
- 网络层 && IP
- Multi view function in blender
- Wireshark packet capturing skills summarized by myself
- Blender's landscape
- JMeter implementation specifies concurrent loop testing
- What does CTO (technical director) usually do?
- The virtual currency evaporated $2trillion in seven months, and the "musks" ended the dream of 150000 people becoming rich
- (待补充)GAMES101作业7提高-实现微表面模型你需要了解的知识
- The most important thing at present
- Failed to open after installing Charles without any prompt
猜你喜欢
Remove the screen recording reminder (seven cattle cloud demo)
一文理解OpenStack网络
C语言-关键字1
Analyse complète Memcached – 2. Comprendre le stockage de mémoire pour Memcached
虚拟机CentOS7中无图形界面安装Oracle(保姆级安装)
123. 买卖股票的最佳时机 III
Direct attack on "three summers" production: good harvest news spreads frequently and summer broadcasting is in full swing
leetcode_191_2021-10-15
【吴恩达笔记】卷积神经网络
Why are life science enterprises on the cloud in succession?
随机推荐
[cloud native learning notes] deploy applications through yaml files
Ebpf XDP mount point analysis
Football information query system based on C language course report + project source code + demo ppt+ project screenshot
EditText controls the soft keyboard to search
多线程收尾
Station B takes goods to learn from New Oriental
Slider控制Animator动画播放进度
leetcode1720_2021-10-14
01---两列波在相遇处发生干涉的条件
升哲科技 AI 智能防溺水服务上线
TCP specifies the source port
AntDB数据库在线培训开课啦!更灵活、更专业、更丰富
how to install clustershell
VirtualBox虚拟机安装Win10企业版
Debugging Analysis of Kernel panics and Kernel oopses using System Map
基于ASP.NET开发的固定资产管理系统源码 企业固定资产管理系统源码
Multi task model of recommended model: esmm, MMOE
Unity about conversion between local and world coordinates
188. 买卖股票的最佳时机 IV
Pattern recognition - 0 introduction