title: vue2.0组件间通信 date: 2017年8月16日 17:57:06 tags: css categories: 教程 author: "JiaWei" vue2.0父子组件及非父子组件间实现通信 1. 父组件与子组件通信 父组件 子组件通过props来接收数据: 格式1: props: ['childMsg'] 格式2 : props: { childMsg: Array //指定传入的类型 } 格式3: props: { childMsg: { type: Array, default: [0,0,0] //指定默认的值 } } ###2.子组件与父组件通信 在vue中是不允许子组件直接修改父组件的值,在vue中只允许单向数据传递 子组件: 父组件: PS vue2.3可以使用.sync修饰符进行子组件改变props值(注意这里是改变。想使用props值的话通过computed进行处理) 3.非父子组件间通信 创建事件中心 组件1触发: 组件2接收: