前端学习-vue视频学习016-vue3新组件
Teleport:让部分元素脱离原来的位置,到to指定的位置去
此处指定了弹窗到body标签内
<template>
<h4>Model</h4>
<button @click="isShow = true">打开弹窗</button>
<Teleport to='body'>
<div class="tanchuang" v-show="isShow">
弹窗
<button @click="isShow = false">关闭弹窗</button>
</div>
</Teleport>
</template>
<script setup name="Model" lang="ts">
import { ref } from 'vue'
let isShow = ref(false)
</script>
<style>
.tanchuang {
padding: 20px 0;
border: 1px solid grey;
border-radius: 5px;
text-align: center;
width: 200px;
position: fixed;
left: 50%;
top: 100px;
margin-left: -100px;
}
</style>
Suspense:当child组件有异步请求,网速较慢时显示较晚,需要有一个类似加载中的展示,使用
child
<template>
<h4>Model</h4>
<div class="tanchuang">
弹窗
<button>关闭弹窗</button>
</div>
</template>
<script setup name="Model" lang="ts">
import { ref } from 'vue'
import axios from 'axios';
let {data} = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
</script>
<style>
.tanchuang {
padding: 20px 0;
border: 1px solid grey;
border-radius: 5px;
text-align: center;
width: 200px;
position: fixed;
left: 50%;
top: 100px;
margin-left: -100px;
}
</style>
Parent
<template>
<div class="app">
<h3>App</h3>
<Suspense>
<template v-slot:default>
<Model/>
</template>
<template v-slot:fallback>
<h3>loading</h3>
</template>
</Suspense>
</div>
</template>
<script setup name="App" lang="ts">
import { Suspense } from 'vue';
import Model from './Model.vue'
</script>
<style>
.app {
padding: 20px 0;
border: 1px solid grey;
border-radius: 5px;
text-align: center;
background: linear-gradient(to right, skyblue, pink);
width: 400px;
height: 400px;
filter: saturate(200%);
}
</style>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!