vue custom v-model

感谢

https://scotch.io/tutorials/add-v-model-support-to-custom-vuejs-component

To let our component support v-model two-way binding, I stated earlier that the component needs to accept a value prop and emit an input event.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<template>
<input @input="handleInput" />
</template>

<script>
export default {
prop: ['value'],
data () {
return {
content: this.value
}
},
methods: {
handleInput (e) {
this.$emit('input', this.content)
}
}
}
</script>