以下代码是如何发送消息:
setup(props, context) {setTimeout(() => {context.emit("showSYCM", "allen");}, 1200);return {};}
以下代码是如何接收消息:
export default {components: {},emits: {showSYCM: val => {console.log(val);return true;}},setup(props, context) {return { showFlag };}
};
</script>
注意,接收消息的函数必须返回true,要不然vue会有警告:
Invalid event arguments: event validation failed for event "showSYCM".
注意:emit函数的第二个参数,可以是一个ref变量,你也可以在接收消息的函数里修改这个ref变量的值。