Created
December 7, 2017 16:15
-
-
Save diverted247/60a90cac17291f1fdf05e96bd50c13cc to your computer and use it in GitHub Desktop.
Vue Component Wrapping <input>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue.component( 'inputtext' , { | |
template:'<input type="text" :value="value" @input="input($event.target.value)" @change="change" @keyup="keyup" @keypress="keypress" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" >', | |
props:['value'], | |
methods:{ | |
input( newInput ){ | |
this.$emit('input', newInput); | |
}, | |
change(){ | |
//console.log( 'change: ' + this.value ); | |
if( this.$el.maxlength && this.$el.value.length > this.$el.maxlength ){ | |
this.$el.value = this.$el.value.slice( 0 , this.$el.maxlength ); | |
} | |
}, | |
keyup(){ | |
//console.log( 'keyup: ' + this.value ); | |
if( this.$el.maxlength && this.$el.value.length > this.$el.maxlength ){ | |
this.$el.value = this.$el.value.slice( 0 , this.$el.maxlength ); | |
} | |
}, | |
keypress(){ | |
//console.log( 'keypress: ' + this.value ); | |
if( this.$el.maxlength && this.$el.value.length >= this.$el.maxlength ){ | |
return false; | |
} | |
return true; | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment