父组件向子组件传递参数,上篇文章说过,这里说下子组件向父组件传递参数
父组件:
<template>
<div>
<child @getMsgs="getWay"></child>
</div>
</template>
<script>
import Child from './child'
export default {
name: "father",
components:{Child},
methods:{
getWay(msg){
console.log(msg)
}
}
}
</script>
<style scoped>
</style>
子组件:
<template>
<div>
<button @click="getMsg">按钮</button>
</div>
</template>
<script>
export default {
name: "child",
data(){
return {
text:"我是子组件向父组件传递参数",
msg:{
number:60,
content:"这是从子组件中传递过来的对象"
}
}
},
methods:{
getMsg(){
this.$emit("getMsgs",this.msg)
}
}
}
</script>
<style scoped>
</style>