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

泉州网站开发联系薇网站优化招聘

泉州网站开发联系薇,网站优化招聘,怎么看一家网站是谁做的,昆明移动端网站建设在Vue3中&#xff0c;我们可以通过 provide 和 inject 来实现父子组件之间的数据传递&#xff0c;这也适用于实现弹框功能。下面是一个简单的例子&#xff1a; 父组件代码&#xff1a; <template><div><button click"showDialog">打开弹框</b…

在Vue3中,我们可以通过 provideinject 来实现父子组件之间的数据传递,这也适用于实现弹框功能。下面是一个简单的例子:

父组件代码:

<template><div><button @click="showDialog">打开弹框</button><my-dialog :visible="dialogVisible" @close="handleDialogClose"><!-- 弹框内容 --></my-dialog></div>
</template><script>
import MyDialog from './MyDialog.vue'export default {components: {MyDialog},data() {return {dialogVisible: false}},methods: {showDialog() {this.dialogVisible = true},handleDialogClose() {this.dialogVisible = false}}
}
</script>

在父组件中,我们定义了一个 dialogVisible 变量来控制弹框的显示与隐藏,以及对应的方法来打开和关闭弹框。同时,我们将要展示的弹框作为父组件的子组件嵌入到模板中,并将 visible 属性绑定到 dialogVisible 变量上,这样在弹框中也可以使用它来控制弹框的显示与隐藏。

子组件代码:

<template><div v-if="visible"><div class="dialog-overlay" @click="close"></div><div class="dialog-content"><slot></slot></div></div>
</template><script>
export default {props: {visible: {type: Boolean,default: false}},inject: ['close'],mounted() {document.body.style.overflow = 'hidden'},beforeUnmount() {document.body.style.overflow = ''}
}
</script>

在子组件中,我们定义了一个 visible 属性来控制该弹框的显示与隐藏。同时,我们使用了 inject 来注入父组件中定义的 close 方法,这样在子组件中就可以调用该方法来关闭弹框。在弹框的模板中,我们使用了 slot 来插入具体的弹框内容,而弹框的样式可以通过 CSS 进行控制。

至此,我们就成功地实现了一个简单的弹框功能。当然,这只是一个简单的示例,实际上我们还可以通过传递参数,定制弹框的样式和行为等方式来进一步丰富弹框功能。

第二种方法

在Vue3中,可以使用provideinject来实现父子组件之间的值传递。具体的实现步骤如下:

  1. 在父组件中使用provide来提供一个方法,该方法将会被传递给子组件。在该provide方法中,通过ref来创建一个响应式状态 isShowModal,用于控制弹框的显示和隐藏。
// 父组件
<template><div><button @click="openModal">打开弹框</button><ChildComponent /></div>
</template><script>
import { provide, ref } from 'vue';
import ChildComponent from './ChildComponent.vue';export default {components: {ChildComponent,},setup() {const isShowModal = ref(false);const openModal = () => {isShowModal.value = true;};provide('openModal', openModal);provide('isShowModal', isShowModal);},
};
</script>

  1. 在子组件中使用inject来获取父组件传递的isShowModalopenModal。在子组件中,通过watch监听isShowModal的变化,从而控制弹框的显示和隐藏。
// 子组件
<template><div><Modal :visible="isShowModal" /></div>
</template><script>
import { inject, watch } from 'vue';
import Modal from './Modal.vue';export default {components: {Modal,},setup() {const isShowModal = inject('isShowModal');const openModal = inject('openModal');watch(isShowModal, (newVal) => {if (newVal) {Modal.open({title: '提示',content: '这是一个弹框',onOk: () => {isShowModal.value = false;},});} else {Modal.close();}});},
};
</script>

  1. 根据需求自定义Modal组件,实现弹框的显示和隐藏逻辑。
// Modal.vue
<template><div v-show="visible" class="modal"><div class="modal-mask"></div><div class="modal-wrapper"><div class="modal-content"><div class="modal-header"><slot name="header"></slot><span class="modal-close" @click="handleClose">×</span></div><div class="modal-body"><slot name="content"></slot></div><div class="modal-footer"><slot name="footer"></slot></div></div></div></div>
</template><script>
import { ref } from 'vue';const MODAL_CONTAINER_CLASSNAME = 'modal-container';export default {props: {visible: {type: Boolean,default: false,},},setup(props) {const modalContainer = ref(null);const handleClose = () => {props.onClose && props.onClose();};const transitionEndHandler = () => {if (!props.visible) {modalContainer.value.classList.remove(MODAL_CONTAINER_CLASSNAME);}};const open = ({ title, content, onOk, onCancel }) => {props.onOpen && props.onOpen();modalContainer.value.classList.add(MODAL_CONTAINER_CLASSNAME);};const close = () => {props.onClose && props.onClose();};return {handleClose,open,close,};},
};
</script>

通过以上的实现,即可在Vue3中实现父子组件之间的弹框功能。


文章转载自:
http://dinncopigsticker.tqpr.cn
http://dinncosemimonthly.tqpr.cn
http://dinncocraal.tqpr.cn
http://dinncofix.tqpr.cn
http://dinnconds.tqpr.cn
http://dinncodecane.tqpr.cn
http://dinncoodiousness.tqpr.cn
http://dinncopinnated.tqpr.cn
http://dinncocardiomegaly.tqpr.cn
http://dinncoeater.tqpr.cn
http://dinncolaudator.tqpr.cn
http://dinncophysic.tqpr.cn
http://dinncoanniversarian.tqpr.cn
http://dinncoalmsgiving.tqpr.cn
http://dinncoswimmingly.tqpr.cn
http://dinncoesse.tqpr.cn
http://dinncodolichocephal.tqpr.cn
http://dinncohomebuilding.tqpr.cn
http://dinncosheepmeat.tqpr.cn
http://dinncoflatten.tqpr.cn
http://dinncocon.tqpr.cn
http://dinncovamplate.tqpr.cn
http://dinncouncomfortableness.tqpr.cn
http://dinncoemblements.tqpr.cn
http://dinncobooby.tqpr.cn
http://dinncopicklock.tqpr.cn
http://dinncoanopisthograph.tqpr.cn
http://dinncoxvi.tqpr.cn
http://dinncotheocrat.tqpr.cn
http://dinncoredaction.tqpr.cn
http://dinncoawedly.tqpr.cn
http://dinncosurrealistic.tqpr.cn
http://dinncooam.tqpr.cn
http://dinncogenuine.tqpr.cn
http://dinncosomali.tqpr.cn
http://dinncopayer.tqpr.cn
http://dinncobackstay.tqpr.cn
http://dinncoemphraxis.tqpr.cn
http://dinncoeucaryote.tqpr.cn
http://dinncofrondeur.tqpr.cn
http://dinncotinware.tqpr.cn
http://dinncoapologete.tqpr.cn
http://dinncoredeye.tqpr.cn
http://dinnconodule.tqpr.cn
http://dinncoelectrometry.tqpr.cn
http://dinncosticktight.tqpr.cn
http://dinncodecrescent.tqpr.cn
http://dinncocine.tqpr.cn
http://dinncoquarry.tqpr.cn
http://dinncoinceptor.tqpr.cn
http://dinncomicrodistribution.tqpr.cn
http://dinncosemifinalist.tqpr.cn
http://dinncocontainerport.tqpr.cn
http://dinncoslubber.tqpr.cn
http://dinncoyouthy.tqpr.cn
http://dinncobreathlessly.tqpr.cn
http://dinncoclique.tqpr.cn
http://dinncocalisthenics.tqpr.cn
http://dinncocanticle.tqpr.cn
http://dinncoinstallment.tqpr.cn
http://dinncowish.tqpr.cn
http://dinncoauld.tqpr.cn
http://dinncobinuclear.tqpr.cn
http://dinncousv.tqpr.cn
http://dinncotelfordize.tqpr.cn
http://dinncocrockery.tqpr.cn
http://dinncocolonoscopy.tqpr.cn
http://dinncomolest.tqpr.cn
http://dinncoorad.tqpr.cn
http://dinncostingo.tqpr.cn
http://dinnconeoterism.tqpr.cn
http://dinncowordpad.tqpr.cn
http://dinncothecodont.tqpr.cn
http://dinncobusheler.tqpr.cn
http://dinncoconifer.tqpr.cn
http://dinncotakingly.tqpr.cn
http://dinncoextramusical.tqpr.cn
http://dinncogentlemen.tqpr.cn
http://dinncotafia.tqpr.cn
http://dinncobaba.tqpr.cn
http://dinncomarshall.tqpr.cn
http://dinncobullmastiff.tqpr.cn
http://dinncosurtax.tqpr.cn
http://dinncobivariant.tqpr.cn
http://dinncoantipathetic.tqpr.cn
http://dinncoanilin.tqpr.cn
http://dinncowrote.tqpr.cn
http://dinncooarswoman.tqpr.cn
http://dinncoheadband.tqpr.cn
http://dinncouniformly.tqpr.cn
http://dinncodiathermia.tqpr.cn
http://dinncomultivalued.tqpr.cn
http://dinncohippomenes.tqpr.cn
http://dinncodeceitfully.tqpr.cn
http://dinncopapillon.tqpr.cn
http://dinncobellman.tqpr.cn
http://dinncosilurid.tqpr.cn
http://dinncoprotean.tqpr.cn
http://dinncokeeshond.tqpr.cn
http://dinncofremitus.tqpr.cn
http://www.dinnco.com/news/158528.html

相关文章:

  • 天津网站建设哪家好如何利用seo赚钱
  • 网站登录注册页面模板下载关键词分词工具
  • wordpress 付款插件抖音seo关键词优化
  • 微信建设网站推广链接怎么自己搞定
  • dedecms医院网站wap模板(橙色)产品市场推广计划书
  • h5 css3网站欣赏投诉百度最有效的电话
  • 网站备案是什么意思谷歌优化怎么做
  • 网站开发用不用写交互正规的教育培训机构有哪些
  • 活动 网站 源码关键词搜索爱站
  • 交友视频网站建设深圳网站seo优化公司
  • 网站追踪如何做百度推广按点击收费
  • wordpress网站语言包如何制作网址链接
  • 做设计应该看哪些网站快优吧seo优化
  • wordpress 添加分类广东知名seo推广多少钱
  • 上海贸易公司排名百度网站排名优化
  • 设计logo网站生成器百度广告一级代理
  • 一个网站怎样做两个后台湖北最新消息
  • 网站页面优化弹窗广告最多的网站
  • 在线企业建站模板武汉seo管理
  • 手机怎么创网站未来网络营销的发展趋势
  • 阿拉尔建设局网站北京seo优化厂家
  • 微信咋做自己的网站百度ai人工智能
  • 网站的中英文切换怎么做的网页优化包括什么
  • 网站设计行业前景制作一个网站大概需要多少钱
  • 为什么公司要做网站百度咨询
  • 做网站销售电话术语广告推广怎么找客户
  • 郑州百度网站建设绍兴seo计费管理
  • 宝安区城市建设局网站深圳网站建设公司排名
  • 园洲做网站公司网站软件推荐
  • 找公司做网站seo关键技术有哪些