Skip to content

v-model语法糖 ​

语法糖: ​

<input type="text" v-model="value">

扩展为: ​

<input type="text" :value="value" @input="value = $event">

子组件: ​

this.$emit('input', $event.target.value)

应用的封装 ​

element弹窗组件抽离的完整写法,使用v-model配合computer的get与set: ​

https://www.jianshu.com/p/f8c9aeb818c2


使用model更改默认的传值 ​

默认向子组件传递props为value,event为input ​

父组件:<my-switch v-model="val"></my-switch> 子组件:props: ['value'] ...... this.$emit('input', 'someVal')

使用model更改默认的传值 ​

js
model: {
        prop: 'diyValue',
        event: 'diyEvent'
 }
// ... 数据传递
this.$emit('diyEvent', 'someVal')