创建子组件公用的空vue变量,为pubVue,并传给需要互相传参/互相调用方法的两个子组件
<template>子组件一 $emit发送事件
<div>
<btn-tools :pubVue="pubVue" />
<table-list :pubVue="pubVue" />
</div>
</template>
<script>
// 组件引用
import TableList from './components/table-list'//组件一
import BtnTools from './components/btn-tools' //组件二
import Vue from 'vue'
export default {
name: 'PDmaterialList',
components: { TableList, BtnTools },
data() {
return {
pubVue: new Vue()
}
}
}
</script>
<template>子组件二 $on监听事件
<div>
<el-button icon="el-icon-search" type="primary" @click="test" />
</div>
</template>
<script>
export default {
props: {
pubVue: {
type: Object
}
},
methods: {
test() {
console.log('方法派发')
this.pubVue.$emit('YOUR_EVENT_NAME', {
name: '张三'
})
}
}
}
</script>
<template>
<div>
<div>子组件二</div>
</div>
</template>
<script>
export default {
props: {
pubVue: {
type: Object
}
},
mounted() {
this.pubVue.$on('YOUR_EVENT_NAME', data => {
console.log('方法监听', data)
})
}
}
</script>
网友回复
python能写一个检测nginx rewrite高危漏洞的工具代码?
css如何给video视频进行mask遮罩?
windows如何同时允许两个用户远程桌面连接同一个电脑?
nginx升级到1.30.1导致无法启动 [emerg] SSL_CTX_new() failed怎么办?
什么是ASLR(地址随机化)?
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?
如何实现类似google的图片隐形水印添加和识别技术?


