我使用vuejs 2,我真的不知道如何从子部件到父母。
我有2个组件: dashboad 和 dashboardpanel 。
in dashboardpanel ,我有一种方法:
execute () {
// emit to parent
this.$emit('executeSQL', this.value)
...
}
和 dashboard :
mounted () {
// get event from DashboardPanel
this.$on('executeSQL', function(value) {
alert(value)
})
}
什么也没发生,我在doc中找不到 $ oon > $,我不知道我是否可以使用其他方法实现它?
您必须在 Dashboard
组件中指定如何从 DashboardPanel
组件中对 executeSQL
事件做出反应。在Dashboard
的HTML模板中:
<DashboardPanel v-on:executeSQL="doExecuteSQL($event)" />
doExecuteSQL
beeing Dashboard
的方法:
methods: {
doExecuteSQL(value) { ... }
}
希望这会有所帮助。