I have a simple component that takes a value prop and shows a textfield for editing it. If the number is below zero I want it to just be zero, if the text is deleted out of the textfield I want it to be zero. In my emit
event, I can see that I am emitting the correct value, it's just not reflected in the textfield itself.
I have a fiddle link here but, the main parts are listed below here:
<div id="app">
<test-component v-model="foo"></test-component>
</div>
const TestComponent = {
props: ['value'],
template: `<div>{{value}}
<input type="number" :value="value" @input="update($event.target.value)" />
</div>`,
methods: {
update(value) {
this.$emit("input", value <= 0 ? 0 : value)
}
}
}
new Vue({
el: "#app",
components: {
'test-component': TestComponent
},
data: {
foo: 1
},
})
Basically what's happening is that I can see my event is being emitted with the value 0, but, and you can see the {{value}} is reflecting what is in the prop, however the printed value in the textfield
itself is empty (or less than zero)
There's definitely something fundamental I'm misunderstanding here, I thought that the :value should reflect reality, but, obviously not. Any help is most appreciated!