3.0.0-beta.20
https://codesandbox.io/s/confident-noether-6i1q7?file=/package.json
Create a new project with the latest Vue.js version.
Create a custom component and add a v-model attribute,
emit a value, the value is not updated in the parent component.
Lets say we have a child component
<template>
<input :value="value" @input="emitUpdates">
</template>
<script>
export default {
props: ["value"],
setup(props, { emit }) {
function emitUpdates(event) {
emit("input", event.target.value);
}
return {
emitUpdates
};
}
};
</script>
And a parent component
<template>
<div>
<Input v-model="state.someText" type="text"/>
{{ state.someText }}
</div>
</template>
<script>
import { reactive } from "vue";
export default {
setup() {
const state = reactive({
someText: "Hallo"
});
return {
state,
};
}
};
</script>
The value of state.someText should get updated if the input value is updated.
This is a working example in Vue2:
https://codesandbox.io/s/custom-input-component-v-model-23x1t
I don't know whether something is changed which is not documented or it is a bug.
The value in the parent component should be updated after emit("input", value) is called.
The value in the parent component is not updated after emit("input", value) is called.
I don't know whether it is expected behavior or not, but it works, when specifying a model
v-model:value="state.someText"
Please read the RFC: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0011-v-model-api-change.md
Most helpful comment
Please read the RFC: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0011-v-model-api-change.md