清新组件库:http://ifresh-ui.yating.online/html
源码地址:https://github.com/Chenyating...git
外部value变化,input的值没有变化?github
先理解v-model的性质ui
<input v-model="searchText"> 等价于 <input v-bind:value="searchText" v-on:input="searchText = $event.target.value" >
组件上使用v-modelthis
<if-input v-model="searchText"></if-input> 等同于 <if-input v-bind:value="searchText" v-on:input="searchText = $event" ></if-input>
要让if-input能正常使用,必须:spa
props: { value:{ type:String, default:'' } },
自定义组件里的input要这么写: <input :value="reciveValue" @input="inputMethod" />
注意:reciveValue=this.value
,要指向value,不这么写,无法双向绑定。双向绑定
data(){ return{ reciveValue:this.value } } inputMethod(e) { this.receiveValue=e.target.value; this.$emit('input', this.receiveValue); }
反正每次值发送变化的时候,就$emit一下code
focusMethod(e) { this.$emit('focus', e) }
clickMethod(e) { this.$emit('click', e) }
keydownMethod(e) { this.$emit('keydown', e) }
inputMethod(e) { if (this.readonly) { this.$emit('input', this.currentValue); } else { this.currentValue = e.target.value; this.$emit('input', this.currentValue); } }
keyupMethod(e) { this.$emit('keyup', e) }
changeMethod(e) { this.$emit('change', e) }
blurMethod(e) { this.$emit('blur', e) }
selectMethod(e) { this.$emit('select', e) }