I'm using recursive components in vue.js. Every component has an array where one value is passed from the parent component as a prop. How do I have to create the array to properly include the value/prop?
Here are the details with simplified (untested) code to show the theoretical problem (I know that this example causes infinite recursion :-):
My-component.vue
<template>
{{my_array}}
<my-component :my_counter="my_array.counter">
</template>
<script>
module.exports = {
props: ['my_counter'],
name: 'my-component',
data: function () {
return {
new_counter: this.my_counter+1,
my_array: [name: "static name", counter: this.new_counter]
}
},
}
</script>
Though new_counter is properly passed as my_counter prop to the child component, the my_array.counter is not properly updated with the new value.
When I pass new_counter as my_counter property directly (without using the array). It works.
I guess I need to use some kind of reactive data. However, I couldn't find a solution with computed properties, methods etc... How can I make my_array updated by the the passed prop?
What is your recommendation to solve this problem?