I like this component:
<template> <div> <p>Current coords: <strong>{{ coords }}</strong></p> <button type="button" @click="updateCoords"> </div> </template> <script> export default { props: { coords: { type: Array, required: true } }, setup(props) { const updateCoords = () => { props.coords = [38.561785, -121.449756] // props.coords.value = [38.561785, -121.449756] } return { updateCoords } }, } </script>
I tried to update the prop coords
value using the updateCoords
method but got the error:
Uncaught TypeError: Cannot set property of undefined (set 'coordinate')
How to update props value correctly in my case?
Props are read-only:
https://v3.vuejs.org/guide/component -props.html#one-way-data-flow
If you want to bind props in two ways, you need to implement the v-model mode:
https://v3-migration.vuejs.org /break-changes/v-model.html#_3-x-syntax