<input v-model="message"> #上下等同 <input :value="message" @input="message = $event.target.value">
<hy-input v-model="message"></hy-input> #上下等同 <hy-input :modelValue="message" @update:model-value="message = $event"></hy-input>
<template> <div> <input :value="modelValue" @input="btnClick"> </div> </template> <script> export default { props: ['modelValue'], emits: ["update:modelValue"], methods: { btnClick(event) { this.$emit("update:modelValue", event.target.value); } } } </script> <style scoped> </style>
<template> <div> <input v-model="value"> <input v-model="why"> </div> </template> <script> export default { props: { modelValue: String, title: String }, emits: ["update:modelValue", "update:title"], computed: { value: { set(value) { this.$emit("update:modelValue", value); }, get() { return this.modelValue; } }, why: { set(why) { this.$emit("update:title", why); }, get() { return this.title; } } } } </script> <style scoped> </style>