Answer the question
In order to leave comments, you need to log in
Why does a parent method called from a child return nothing to the child?
Good afternoon.
I guess I'm trying to misuse parent and child, BUT I want to ask anyway.
So there is, a descendant:
// IterableTableTemplate.vue (child)
<template>
<!--//-->
<tr v-for="item in items" :key="item._id">
<td v-for="(field, keyField) in fields" :key="keyField">{{ calcSomething(item, keyField) }}</td>
</tr>
<!--//-->
</template>
<script>
// ...imports
export default {
props: {
items: Array,
fields: Object
},
methods: {
calcSomething: function(item, field) {
this.$emit("getSomething", item, field)
}
/*, // если код прописать прямо в потомке, то всё работает
calcSomething: function(job, field) {
return "111"
}
*/
}
</script>
//parent.vue
<template>
<IterableTableTemplate :items="jobs" :fields="fields" @getSomething="doSomething">
</IterableTableTemplate>
</template>
<script>
//...imports
export default {
data() {
return {
jobs,
fields
}
},
methods: {
doSomething: function(job, field) {
console.log(job, field) // отрабатывает job и field есть
return "111" // НО ничего не возвращает
}
}
</script>
Answer the question
In order to leave comments, you need to log in
Where is he supposed to return it?
It should work well, but where will it return?
The result of this function is not used anywhere and cannot be used unless something is done in the function itself.
emit only throws an event, the parent is raised to the event, but this has nothing to do with anything, completely different processes.
And the @getSomething handler is simply executed, and its result goes nowhere.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question