Vue.component('base-input', {
model: {
prop: 'text',
event: 'input'
},
template: `
<label>
请输入:
<input type="text" v-bind:value="text" @input="$emit('input', $event.target.value)" />
</label>
`,
props: {
text: String,
},
})
let vm = new Vue({
el: "#app",
data: {
message: 'hello',
localText: ''
}
})
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<div id="app">
{{ message }}
<base-input v-model="localText" />--- {{ localText }}
</div>