This repository was archived by the owner on Nov 10, 2020. It is now read-only.
File tree 1 file changed +10
-17
lines changed
1 file changed +10
-17
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
- <input type =" text" @blur =" onBlur" >
2
+ <input type =" text" @blur =" onBlur" @input = " onInput " >
3
3
</template >
4
4
5
5
<script >
31
31
},
32
32
},
33
33
data () {
34
- return {
35
- onChangeFn: null
36
- }
34
+ return {}
37
35
},
38
36
mounted () {
39
- // Backup onChange callback
40
- this .onChangeFn = this .options .onChange ;
41
- // Inject our onChange callback
42
- let newOptions = jQuery .extend (true , {}, this .options , {onChange: this .onChange });
37
+ // Clone configs
38
+ let newOptions = jQuery .extend (true , {}, this .options );
43
39
// Lastly init the mask
44
40
jQuery (this .$el ).mask (this .mask , newOptions);
45
41
// Set initial value
46
42
jQuery (this .$el ).val (jQuery (this .$el ).masked (this .value ));
47
43
},
48
44
methods: {
49
45
/**
50
- * Update v-model upon change triggered by plugin itself
46
+ * Update v-model upon change triggered by user
51
47
*/
52
- onChange (... args ) {
53
- let toEmit = this .raw ? jQuery (this .$el ).cleanVal () : arguments [0 ];
54
- this .$emit (' input' , toEmit);
55
-
56
- if (typeof this .onChangeFn === ' function' ) {
57
- this .onChangeFn .call (this , ... args)
58
- }
48
+ onInput (event ) {
49
+ this .$nextTick (() => {
50
+ let toEmit = this .raw ? jQuery (this .$el ).cleanVal () : event .target .value ;
51
+ this .$emit (' input' , toEmit);
52
+ });
59
53
},
60
54
onBlur (event ) {
61
55
this .$emit (' blur' , this .value )
72
66
},
73
67
beforeDestroy () {
74
68
jQuery (this .$el ).unmask ();
75
- this .onChangeFn = null
76
69
}
77
70
}
78
71
</script >
You can’t perform that action at this time.
0 commit comments