$emit
this.$emit('事件名称', 参数);
setTextEvent
setText
<template> <h3>父组件</h3> <p> {{ text }} </p> <Son @setTextEvent="setText"> </Son> </template> <script> import Son from "./Son.vue"; export default { name: "Father", components: { Son }, data() { return { text: '' } }, methods: { setText(text) { this.text = text; } } } </script>
<template> <button @click="setText">子组件触发 emit</button> </template> <script> export default { name: "Son", methods: { setText() { // 父组件绑定的 emit 事件是 setTextEvent this.$emit('setTextEvent', 'hello') } } } </script>