
在父页定义一个自定义事件,比如showPlatform
<taskpage1 @showPlatform="setPlatform"></taskpage1>
这里的taskpage1是子页面,是个组件页,然后写个事件
setPlatform: function (msg) {
this.platform = msg
}
然后,我们就可以在组件页中使用以下语句激活父页的事件并传值了
this.$emit('showPlatform', '需要传过去的内容')
父页向子页传输数据,则是子页通过props进行接收。
父页中绑定属性,如:
:xxx="platform"
子页中用props来获取:
props: {
xxx: String,
required: true
}
如此,就实现了父页与子页的数据传递。