I’m trying to pass as a prop attribute some input fields and emit it to the parent component, but can’t edit the input fields. I’m passing props down as a titled v-model to the child component. I think I’m wrong with the logic and reading correctly the docs, just can’t get it. When I’m typing the input nothing remains in the input field.
function fullname() {
return {
fullname: {
firstname: 'Adam',
lastname: 'Coll'
}
}
}
export { fullname }
Parent component
<template>
<Child
v-model:windDirectionDep="names.fullname.firstname"
v-model:windDirectionArr="names.fullname.lastname"/>
</template>
<script>
import { name as setName } from '../'
data () {
return {
names: {}
}
},
methods: {
setName () {
this.names = setName()
}
},
created () {
this.setName()
},
</script>
Child component
<template>
<q-input
name="firstname"
:value="windDirectionDep"
@update:model-value="(value) => emit('update:windDirectionDep', value)" />
<q-input
name="lastname"
:value="windDirectionArr"
@update:model-value="$emit('update:windDirectionArr', $event)" />
</q-input>
</template>
<script>
props: [
'windDirectionDep',
'windDirectionArr'
],
</script>
2
Answers
The Quasar
<q-input>
component is not the same as the native HTML<input>
and should not be assumed to emit the same events.If you check the q-input API under the "Events" tab you can see all the events you can listen to. The one you want is
@update:model-value
. The model value will also not be on$event.target.value
but will just be$event
.Your q-input should then look something like:
Try this way. Instead of using
:value
and@update:model-value
you can usecomputed
way as explained hereNote that I used pascal-case (
wind-direction-dep
andwind-direction-arr
) for v-model arguments