Answer the question
In order to leave comments, you need to log in
How to update data between components?
I have 2 components. The first is tied to creation and updating. That is, when creating, I send the data (all data must be empty), but when I update (I reuse this component), I substitute the data that I received. Just comparison operators. If I have data, then I use it (this is an update), if there is no data, then I use an empty string.
for example
data() {
return {
title: '' || this.data.title,
value: null || this.data.tags,
}
}
Answer the question
In order to leave comments, you need to log in
Store data in a store (Vuex) and get it through mapState where you need it and after filling it, just update it through a mutation?
Then absolutely no difference, child, parent component. You simply control the logic of a particular component based on the data of the store
If you don't need to use Vuex then you can use Props
Pass like this
<template>
<component-first data="{ "key": "data" }"></component-first>
</template>
<<script>
export default {
components: {
ComponentFirst
}
}
</script>
<template>
<p>{{ data }}</p>
</template>
<<script>
export default {
props: {
data: Array
},
setup (props) {
// work
}
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question