vue弹窗 父子组件调用

目录

一、vue弹窗 父子组件 emit 传图片

二、vue父组件调用子组件里的不同方法


一、vue弹窗 父子组件 emit 传图片

1、:modal-append-to-body="false"为了解决element ui中引入dialog窗口组件后遮罩层会挡住dialog窗口的用处,默认为true,改为false即可解决。

2、此弹窗主要为了解决收到下位机急停信号后,上位机前台显示弹窗的重复性。

//此为子组件(customComponents.vue)
<div>
    <el-dialog 
        :visible.sync="dialogVisible" 
        width="25%" 
        :modal-append-to-body="false">

		<div slot="title" class="dialog-header-title">
		   <img  :src="url" >
		   <span>&nbsp;提示</span>
		</div>
		<span>{
  {this.message}}</span>
	    <span slot="footer" class="dialog-footer">
		    <el-button 
                type="primary" 
     
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是Vue3中父子组件之间的调用方法: 1. 组件组件传参: 在组件中使用props属性将数据传递给组件,在组件中通过props接收数据。 ```vue // 组件 <template> <div> <child-component :message="message"></child-component> </div> </template> <script> import ChildComponent from './ChildComponent.vue'; export default { components: { ChildComponent }, data() { return { message: 'Hello from parent component' }; } }; </script> // 组件 <template> <div> <p>{{ message }}</p> </div> </template> <script> export default { props: ['message'] }; </script> ``` 2. 组件调用组件内的方法: 在组件中使用ref属性给组件命名,然后在组件中通过$refs来调用组件的方法。 ```vue // 组件 <template> <div> <child-component ref="child"></child-component> <button @click="callChildMethod">Call Child Method</button> </div> </template> <script> import ChildComponent from './ChildComponent.vue'; export default { components: { ChildComponent }, methods: { callChildMethod() { this.$refs.child.childMethod(); } } }; </script> // 组件 <template> <div> <p>Child Component</p> </div> </template> <script> export default { methods: { childMethod() { console.log('Child method called'); } } }; </script> ``` 3. 组件调用组件的方法: 在组件中使用v-on指令给组件绑定一个自定义事件,在组件中通过$emit方法触发该事件,并传递数据给组件。 ```vue // 组件 <template> <div> <child-component @custom-event="handleCustomEvent"></child-component> </div> </template> <script> import ChildComponent from './ChildComponent.vue'; export default { components: { ChildComponent }, methods: { handleCustomEvent(data) { console.log('Custom event received:', data); } } }; </script> // 组件 <template> <div> <button @click="emitCustomEvent">Emit Custom Event</button> </div> </template> <script> export default { methods: { emitCustomEvent() { this.$emit('custom-event', 'Custom data'); } } }; </script> ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值