一,父组件向子组件传值
1⃣️,静态的传值props

2⃣️,动态的传值props
要动态地绑定父组件的数据到子模板的props用 v-bind。每当父组件的数据变化时,该变化也会传导给子组件)

二,子组件向父组件传值
使用v-on绑定自定义事件,每个Vue实例都实现了事件接口,即:
使用$on(eventName)监听事件
使用$emit(eventName)触发事件

transferUser 是一个自定义的事件,功能类似于一个中转,this.msg 将通过这个事件传递给父组件

网友评论