问题实例:
// 子组件
<template>>
<div @click.stop="sendInfo">我是子组件</div>
</template>
<script>
export default {
methods: {
sendInfo(){
this.$emit('sendInfo',{message:'childdata'})
}
}
}
// 父组件
<template>>
<child @sendInfo="hanldeInfo('test1')"/>
</template>
<script>
import Child from './child.vue'
export default {
components: {
Child
},
methods: {
hanldeInfo(data1){
console.log(data1) // test1
}
}
}
</script>
处理办法: 在监听的调用上第一个实参写为$event,后面写你需要额外添加的参数即可
// 父组件
<template>>
<child @sendInfo="hanldeInfo($event,'test1')"/>
</template>
<script>
import Child from './child.vue'
export default {
components: {
Child
},
methods: {
hanldeInfo(data1,data2){
console.log(data1,data2) // {message:'childdata'}, test1
}
}
}
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)