当前位置: 首页 > news >正文

做资源网站需要什么金华网站建设

做资源网站需要什么,金华网站建设,担路网做网站多少钱,信息类网站 wordpress<Teleport></Teleport> 作用目的&#xff1a; 用于将指定的组件或者元素传送到指定的位置&#xff1b; 通常是自定义的全局通用弹窗&#xff0c;绑定到 body 上&#xff0c;而不是在当前元素上面&#xff1b; 使用方法&#xff1a; 接收两个参数 to: 要将目标传…
<Teleport></Teleport>  

作用目的:

用于将指定的组件或者元素传送到指定的位置;
通常是自定义的全局通用弹窗,绑定到 body 上,而不是在当前元素上面;

使用方法:

接收两个参数
to: 要将目标传到的位置; 可以是指定的元素、class、id
disabled: 是否禁止将目标传送到指定位置;Boolean

比如:

<Teleport 
to="body"
disabled="true"
></Teleport>

而为什么要使用teleport 内置组件呢?

比如:有这样一个需求,我们需要一个盒子顺时针旋转 45度;而这个盒子同时是一个弹窗的父级组件,并且这个盒子可以打开改弹窗;

父组件:

<template>
<div class="my-built-in"><!-- 内置组件 --><div class="other-place" @click="handleOpen">其他dom位置<TelDialog :isShowTel="isShowTel":telCon="telCon" @onCloseDialog="handleClose"></TelDialog></div>
</div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import TelDialog from './components/telDialog.vue'
const isShowTel = ref(false)
const telCon = ref('This is a Teleport component.')
const handleClose = () => {isShowTel.value = false
}
const handleOpen = () => {isShowTel.value = true
}
</script>
<style lang='scss' scoped>
.my-built-in{position: relative;width: 100px;height: 100px;background-color: #00ff00;left: 200px;transform: rotate(45deg);
}</style>

弹窗组件:

<template><div class="my-tel-container" v-if="props.isShowTel"><div class="my-tel-title">Teleport 弹窗</div><div class="my-tel-content">{{ props.telCon }}</div><div class="my-tel-foot"><el-button type="primary" class="close-btn" @click="handleClose">关闭teleport 弹窗</el-button></div></div>
</template>
<script setup>
import { ref } from 'vue'
const props = defineProps({isShowTel:{type: Boolean,default: false,},telCon: {type: String,default: ''}
})
const emits = defineEmits(['onCloseDialog'])
const handleClose = () => {emits('onCloseDialog')
}
</script>
<style lang='scss' scoped>
.my-tel-container{position: fixed;top:50%;left: 50%;width: 440px;height: auto;background-color: aqua;box-shadow: 0 2px 4px 0 rgba(0,0,0, .3);box-sizing: border-box;padding: 0 16px 16px;.my-tel-title{width: 100%;height: 46px;text-align: center;line-height: 46px;font-size: 16px;color: #333;}.my-tel-content{width: 100%;height: 200px;}.my-tel-foot{width: 100%;height: 46px;display: flex;justify-content: right;align-content: center;}
}
</style>

我们会发现写好之后在没有使用teleport 组件的情况下 弹窗也跟着旋转了45度,这并不是我们想要的;为什么会出现这种情况呢?
如图:
请添加图片描述

我们需要的是即使父组件发上了旋转 位移等,弹窗依然是位于浏览器的正中央;
此时我们就可以通过 <Teleport></Teleport> 组件来将弹窗组件实际渲染的位置更改到 body 上;但是这样并不影响 组件直接的通讯;

更改父组件为:

<template>
<div class="my-built-in"><!-- 内置组件 --><div class="other-place" @click="handleOpen">其他dom位置<!-- **只需要添加 Teleport 组件即可,disabled 接收一个布尔值,默认是falsetrue代表不传送到指定位置 body上** --><Teleport to="body" :disabled="false"><TelDialog :isShowTel="isShowTel":telCon="telCon" @onCloseDialog="handleClose"></TelDialog></Teleport></div>
</div>
</template>

请添加图片描述

注意事项:

a、在使用teleport 组件时,需要确保传送的位置dom已经渲染完成,即to的位置dom已完成渲染,否则将无法实现传送;
b、同时可以通过给disabled 动态传入一个Boolean 值,来控制是否要将元素或dom传送到指定的位置;

http://www.hengruixuexiao.com/news/19269.html

相关文章:

  • 光辉网站建设公司外链吧官网
  • 网站改版提交 百度合肥网站推广电话
  • 用网站做的人工智能it培训机构哪个好一点
  • 优秀政府网站欣赏全国疫情最新报告
  • 网站添加wordpress网站设计优化
  • wordpress的wap插件windows优化大师怎么彻底删除
  • 广州网站建设外包电话营销系统
  • 网站服务器代码放在哪电商平台排行榜
  • 网页游戏网页游戏大全青岛的seo服务公司
  • 石家庄网站建设咨询薇百度知道官网首页登录入口
  • 三级分销网站制作seo领导屋
  • 网页建设与网站设计信阳seo公司
  • 北京网页设计设计培训seo免费培训教程
  • php做网站首页的代码如何优化
  • 做网站需要ftp如何优化网站推广
  • 佛山公司注册网页宁波网站推广网站优化
  • xunsearch做搜索网站网络营销是指
  • 重庆公司注册网站可以免费发帖的网站
  • 做中国o2o网站领导官网seo
  • 可玩儿小程序可以加盟么长沙网络优化产品
  • 企业网站seo参考文献武汉百度推广多少钱
  • 公司网站主页排版网站外链优化方法
  • 邹平 建设项目 网站公示广州网站建设正规公司
  • 北京网站建设首选石榴汇网站优化塔山双喜
  • 如何进行新产品的推广免费seo软件推荐
  • 天津建设网站公司关键词在线挖掘网站
  • 住房与建设部网站首页开发一款app软件需要多少钱
  • 网站建设计划表昭通网站seo
  • 建设网站那个好云服务器免费
  • 做淘客网站哪个cms好微博推广方法有哪些