vue里面的作用域都是孤立的,不允许在子组件的模板内直接使用父组件的数据.必须使用特定的方法来实现父子组件之间的数据传递.
1.父组件可以使用props来向子组件传值,父组件中用v-bind来绑定传给子组件的值:

子组件通过props接收父组件传过来的值:

或者是给props添加一些通用的规则:

2.子组件向父组件传递数据
子组件触发事件,使用$emit来遍历自定义的事件"closeSendChange",并且返回参数false,这个自定义事件就相当于一个中转

父组件监听子组件的事件:

网友评论