Background: Vue ES6, the child component is called after the parent component is created, and the event trigger onclick has been encapsulated in the underlying component (the child component of the child component)
Question: How does a child component pass parameters to the parent component when there is no event binding in the parent component?
仅有的幸福2017-05-19 10:22:59
EventBus (a situation without event binding that does not quite meet the requirements of the question)
Vuex
滿天的星座2017-05-19 10:22:59
The child component uses v-on to listen to an event, and then when it is triggered, it sends the event, which is $emit. Then the parent component also uses v-on to listen to the event you send, and then executes the event defined by your parent component.
伊谢尔伦2017-05-19 10:22:59
The person above has made it clear, I’m here to make up for itchild.vue
<template>
<p id="test">向父传递</p>
</template>
<script>
export default {
methods: {
$('#test').click(()=>{
this.$emit('data', '这是我要传的参数');
})
}
}
</script>
parent.vue
<template>
<child @data="fnSS"></child>
</template>
<script>
import child from './child';
export default {
components: {
tagInput
}
methods: {
fnSS(value) {
alert(value);
},
}
}
</script>