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

做美容网站公司百度指数分析报告

做美容网站公司,百度指数分析报告,娇娇王妃驾到撩拨王爷脸红心跳,百度怎样收录到网站在Element UI中,如果多个父子组件共用一个el-dialog弹窗,并且需要在切换组件页面时关闭弹窗,你可以考虑以下方法来实现: 使用Vuex进行状态管理: 在Vuex中创建一个状态来管理弹窗的显示状态(例如&#xff0…

在Element UI中,如果多个父子组件共用一个el-dialog弹窗,并且需要在切换组件页面时关闭弹窗,你可以考虑以下方法来实现:

使用Vuex进行状态管理:

在Vuex中创建一个状态来管理弹窗的显示状态(例如,showDialog)。 在父子组件中都可以访问这个状态,以便共享。
当需要打开或关闭弹窗时,分发对应的Vuex mutation 来更新showDialog状态。
在el-dialog中使用v-if或v-show根据showDialog的值来控制弹窗的显示与隐藏。

// store.js
import Vue from 'vue';
import Vuex from 'vuex';Vue.use(Vuex);export default new Vuex.Store({state: {showDialog: false,},mutations: {toggleDialog(state) {state.showDialog = !state.showDialog;},},
});

在父子组件中使用 mapState 和 mapMutations 来访问和修改 showDialog 状态:

// ParentComponent.vue
<template><div><button @click="toggleDialog">Toggle Dialog</button><child-component></child-component><el-dialog :visible="showDialog" @close="toggleDialog"><!-- 弹窗内容 --></el-dialog></div>
</template><script>
import { mapState, mapMutations } from 'vuex';export default {computed: {...mapState(['showDialog']),},methods: {...mapMutations(['toggleDialog']),},
};
</script>
// ChildComponent.vue
<template><div><button @click="toggleDialog">Toggle Dialog</button></div>
</template><script>
import { mapMutations } from 'vuex';export default {methods: {...mapMutations(['toggleDialog']),},
};
</script>

事件总线:

创建一个事件总线(Event Bus)作为Vue实例,使得不同组件可以通过该事件总线进行通信。
在需要打开或关闭弹窗的地方,触发事件,然后在el-dialog所在的组件中监听这些事件,以控制弹窗的显示与隐藏。

// EventBus.js
import Vue from 'vue';
export default new Vue();

在需要打开或关闭弹窗的地方触发事件:

// ParentComponent.vue
<template><div><button @click="toggleDialog">Toggle Dialog</button><child-component></child-component><el-dialog :visible="showDialog" @close="toggleDialog"><!-- 弹窗内容 --></el-dialog></div>
</template><script>
import EventBus from './EventBus';export default {data() {return {showDialog: false,};},methods: {toggleDialog() {this.showDialog = !this.showDialog;EventBus.$emit('toggle-dialog', this.showDialog);},},
};
</script>
// ChildComponent.vue
<template><div><button @click="toggleDialog">Toggle Dialog</button></div>
</template><script>
import EventBus from './EventBus';export default {methods: {toggleDialog() {EventBus.$emit('toggle-dialog', true);},},
};
</script>

在el-dialog所在的组件中监听事件:

// AnyComponent.vue
<template><el-dialog :visible="showDialog" @close="toggleDialog"><!-- 弹窗内容 --></el-dialog>
</template><script>
import EventBus from './EventBus';export default {data() {return {showDialog: false,};},created() {EventBus.$on('toggle-dialog', (showDialog) => {this.showDialog = showDialog;});},
};
</script>

使用provide和inject:

在父组件中使用provide来提供一个控制弹窗显示的方法,或者提供一个布尔值的ref。
在子组件中使用inject来获取这些提供的数据。
子组件可以调用提供的方法或者监听提供的ref来控制弹窗的显示与隐藏。

在父组件中使用provide来提供一个方法或ref:

// ParentComponent.vue
<template><div><button @click="toggleDialog">Toggle Dialog</button><child-component></child-component><el-dialog :visible="showDialog" @close="toggleDialog"><!-- 弹窗内容 --></el-dialog></div>
</template><script>
export default {provide: {toggleDialog: this.toggleDialog, // 方法showDialogRef: this.showDialogRef, // ref},data() {return {showDialog: false,showDialogRef: ref(false),};},methods: {toggleDialog() {this.showDialog = !this.showDialog;this.showDialogRef.value = this.showDialog;},},
};
</script>

在子组件中使用inject来获取这些提供的数据:

// ChildComponent.vue
<template><div><button @click="toggleDialog">Toggle Dialog</button></div>
</template><script>
import { inject } from 'vue';export default {setup() {const { toggleDialog, showDialogRef } = inject();const toggleDialogInParent = () => {toggleDialog();};return {toggleDialogInParent,showDialogRef,};},
};
</script>
http://www.qdjiajiao.com/news/12490.html

相关文章:

  • 哪些网站是用vue做的南昌seo
  • 如何做网站的源码外贸推广营销公司
  • wordpress 社区关键词优化意见
  • 化妆品网站开发流程和进度安排百度推广找谁
  • 银川360推广 网站建设市场监督管理局
  • 计算机网络技术电商网站建设与运营全国疫情排名一览表
  • 北京集团公司网站建设网站推广软文
  • 衡水提供网站制作公司哪家专业郑州seo方案
  • 个人可以做电影网站吗爱站seo工具包官网
  • 成都淮洲新城建设投资有限公司网站企业软文营销发布平台
  • 宁波做网站的专业公司网站关键词优化办法
  • 烟台网站建设技术托管公司专业网站建设
  • 做百家好还是个人网站国际国内新闻最新消息今天
  • 流媒体 网站开发麒麟seo
  • 网站关键词优化原理长春网络营销公司
  • 宝鸡市建设工程交易中心网站谷歌浏览器 安卓下载
  • iis7 多个网站 80端口做网站好的网站建设公司
  • qq空间网站是多少营业推广的形式包括
  • 做网站西安网站推广平台排行
  • 设计网站私单价格google搜索引擎优化
  • 哪个网站可以做经济模拟题无锡seo公司
  • 关于网站建设的新闻河南网站建设哪里好
  • 从零开始自己做外贸网站和海外网络营销哈尔滨百度推广联系人
  • 腾讯云如何建设网站六盘水seo
  • wordpress 好用的插件推荐百度seo排名优化公司哪家强
  • 网站规划和建设b站24小时自助下单平台网站
  • 网站 空间苏州seo优化公司
  • b2b能给网站做优化吗外链购买平台
  • 有没有一些帮做名片的网站如何做好网络营销管理
  • 网站后台 生成所有页面西安网络公司