例子:模拟UI框架对话框组件。
App.vue
<style>
.app{
background-color:gray;
padding:10px;
}
</style>
<template>
<div class="app">
<h3>我是App组件</h3>
<Child/>
</div>
</template>
<script>
import Child from './components/Child'
export default{
name:'App',
components:{
Child
},
}
</script>
Child.vue
<style>
.Child{
background-color:skyblue;
padding:10px;
}
</style>
<template>
<div class="Child">
<h3>我是Child组件</h3>
<Son/>
</div>
</template>
<script>
import Son from './components/Son'
export default{
name:'Child',
components:{
Son
},
}
</script>
Son.vue
<style>
.Son{
background-color:skyblue;
padding:10px;
}
</style>
<template>
<div class="Son">
<h3>我是Son组件</h3>
<Son/>
</div>
</template>
<script>
import Son from './components/Son'
export default{
name:'Son',
components:{
Son
},
}
</script>
Dialog.vue
<style>
.dialog{
position:absolute; //绝对定位
text-align:center;
top:50%;
left:50%;
transform:translate(-50%, -50%)
width:300px;
height:300px;
background:green;
}
.mask{
position:absolute; //绝对定位
top:0;
bottom:0;
left:0;
right:0;
background:rgba(0,0,0,0);
}
</style>
<template>
<div>
<buttuon @click="isShow=true">弹出对话框</button>
<teleport to='body'>
<div class='mask' v-if="isShow">
<div class="dialog">
<h3>我是一个弹窗</h3>
<button @click="isShow=false">关闭弹窗</button>
</div>
</div>
</teleport>
</div>
</template>
<scripct>
import {ref} from 'vue'
export default{
name:'Dialog',
setup(){
let isShow = ref(false)
return {isShow}
}
}
</scripct>
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- azee.cn 版权所有 赣ICP备2024042794号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务