Skip to content

Instantly share code, notes, and snippets.

@Polkovn1k
Last active March 22, 2023 18:32
Show Gist options
  • Save Polkovn1k/1af468dcd26a51bd5e9a7536dcad911f to your computer and use it in GitHub Desktop.
Save Polkovn1k/1af468dcd26a51bd5e9a7536dcad911f to your computer and use it in GitHub Desktop.
Emit child function in parent (VUE)
<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