清新組件庫: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) }