1.ref
父组件操作子组件:
<子组件 ref='名称'></子组件>
在父组件中可以通过:this.$refs.名称
(react: this.refs.名称)
子组件操作父组件:
this.$parent.属性或this.$emit('toFather','来自子组件的数据')
练习:
简单的聊天室
分析组件构成:
chat-room父组件
lucy 子组件:名称+input+按钮
mike 子组件:名称+input+按钮
功能实现:
目标:将子组件中用户输入的信息,发送之后,显示在chat-room的列表中。
数据存储在数组中:chat-room
数据操作:子组件点击发送时 往数组中插入数据
1.子组件与父组件通信:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Chat Room</title>
<style></style>
</head>
<body>
<div id="example">
<chat-room></chat-room>
</div>
<script type="text/x-template" id="cha