vueJs使用

组件上使用v-model

2020-05-09  本文已影响0人  记录学习生活

我们要怎么做才能在组件上使用v-model呢?

很简单,当input-component触发input事件时,我们让他发布一个input事件,并带上$event.target.value,在父组件上,我们用v-model监听这个input事件,就能实现了

子组件:<input type="text":value="value" @input="$emit('input', $event.target.value);">

父组件:<input-componentv-model="value">

上一篇 下一篇

猜你喜欢

热点阅读