I have a custom component that takes the modelValue prop and emits the update:modelValue event. In the parent component I pass an array:
TestComponent.vue
<template>
<div>
<button @click="updateIt">Test</button>
</div>
</template>
<script>
export default {
props: {
modelValue: Array
},
emits: ["update:modelValue"],
setup(props, {emit}){
return {
updateIt(){
emit("update:modelValue", [4,5,6])
}
}
}
}
</script>
App.vue
<template>
<div>
<test-component v-model="myArr"/>
<ul>
<li v-for="i in myArr" v-text="i"></li>
</ul>
</div>
</template>
<script>
import TestComponent from "./TestComponent.vue";
export default {
components: {
TestComponent
},
setup(props, {emit}){
const myArr = reactive([1,2,3]);
return {
myArr
}
}
}
</script>
The list will not get updated when I press the button, why?