🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] #### 自定义组件的 v-model ~~~ <template> <div class="input-wrapper"> <section class="form-input"> <input :type="type" :placeholder="placeholder" :maxlength="maxlength" @input="$emit('input', $event.target.value)" > <button class="code-btn" :class="{disabled: disabled}" :disabled="disabled" v-if="codebtn" @click="$emit('btnClick')">{{code}}</button> </section> <div class="errors" v-if="errors">{{errors}}</div> </div> </template> ~~~ >[danger] 自定义组件中,有input表单,外部调用要进行v-model双向绑定时,必须在组件中把input事件发布出去 @input="$emit('input', $event.target.value)" 并把当前值携带出去,父组件就可以用v-model监听表单实时变化的值