When I’m using ‘ref’ – value doesn’t updating from props.
When using ‘toRef’ – value doesn’t updating from user inputting.
Watch, computed – the same…
I was only able to solve this by introducing an additional variable and using watch method:
<template>
<input
v-model="inputVal"
@change="$emit('change-val', inputVal)"
type="text"
>
</template>
<script>
import { ref, toRef, watch } from 'vue'
export default {
name: 'RefInput',
props: {
val: [String, Number, Array]
},
setup(props) {
const propsVal = toRef(props, 'val')
const inputVal = ref(propsVal.value)
watch(propsVal, (propsVal) => {
inputVal.value = propsVal
})
return{
inputVal
}
}
}
</script>