0

<user-data @change="setUserInfo"></user-data"> this is the child component where have used emits to pass data.

here is the method of parent component.

 setUserInfo(data) {
   this.obj.payment_details = data;
 },

is it possible to bind data from the above method?

export default {
    data: () => ({
        dialog: false,
        obj: new Expense(),
        saveLoader: false,
    }),
}
2
  • What do you want to say with is it possible to bind data from the above method?. What result you want? Commented Oct 17, 2022 at 9:54
  • 1
    Usually, you use emits+props. Then, the parent/child relationship is a matter of reactive by default if properly done. No extra work needed. Commented Oct 17, 2022 at 10:07

1 Answer 1

2

Here you have an example on how to emit data from child component to parent (using Vue3 Composition API script setup):

Parent:

<template>
  <Comp @my-var="callback" />
  
  {{ test }}
</template>

<script setup>
import { ref } from 'vue'
import Comp from './Comp.vue'
const test = ref('')

const callback = data => test.value = data
</script>

Child:

<template>
<button
  v-text="'click'"
  @click="doEmit()"
/>
</template>

<script setup>
const emits = defineEmits(['myVar'])

const doEmit = () => emits('myVar', 'emiting this data')
</script>

Check out the Playground

Sign up to request clarification or add additional context in comments.

1 Comment

am on vue2 is it possible too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.