Last active
March 22, 2023 18:32
-
-
Save Polkovn1k/1af468dcd26a51bd5e9a7536dcad911f to your computer and use it in GitHub Desktop.
Emit child function in parent (VUE)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="app"> | |
<child-component ref="childComponent"></child-component> | |
<button @click="someParentAction">Click</button> | |
</div> | |
</template> | |
<script> | |
/* --Child Component*/ | |
let ChildComponent = { | |
template: '<div>{{value}}</div>', | |
data: function () { | |
return { | |
value: 0 | |
}; | |
}, | |
methods: { | |
setValue(value) { | |
this.value = value; | |
} | |
} | |
} | |
/* --Parent Component*/ | |
new Vue({ | |
el: '#app', | |
components: {ChildComponent}, | |
methods: { | |
someParentAction() { | |
this.$refs.childComponent.setValue(2.0); | |
} | |
} | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment