9
9
@input =" input"
10
10
/>
11
11
</template >
12
-
13
12
<script lang="ts">
14
- import { defineComponent } from ' vue'
13
+ import { defineComponent , ref , computed } from ' vue'
15
14
import { cloneDeep , CustomInputEvent , Input } from ' ./core'
16
15
import directive from ' ./directive'
17
16
import defaultOptions from ' ./options'
@@ -30,7 +29,8 @@ export default defineComponent({
30
29
},
31
30
nullValue: {
32
31
type: [Number , String ],
33
- default : () => options .nullValue
32
+ required: false ,
33
+ default: options .nullValue
34
34
},
35
35
masked: {
36
36
type: Boolean ,
@@ -78,42 +78,31 @@ export default defineComponent({
78
78
}
79
79
},
80
80
emits: [' update:model-value' , ' input:model-value' ],
81
- data() {
82
- return {
83
- maskedValue: this .modelValue ,
84
- unmaskedValue: ' ' as Input | undefined
81
+ setup(props , { emit }) {
82
+ const maskedValue = ref (props .modelValue )
83
+ const unmaskedValue = ref (' ' as Input | undefined )
84
+ const config = computed (() => ({ ... props }))
85
+
86
+ const emittedValue = computed (() => {
87
+ return props .masked ? maskedValue .value : unmaskedValue .value
88
+ })
89
+
90
+ const input = (event : Event ) => {
91
+ const { target } = event as CustomInputEvent
92
+ maskedValue .value = target .value
93
+ unmaskedValue .value = target .unmaskedValue
94
+ emit (' input:model-value' , emittedValue )
85
95
}
86
- },
87
- computed: {
88
- emittedValue() {
89
- return this .masked ? this .maskedValue : this .unmaskedValue
90
- },
91
- config() {
92
- return {
93
- nullValue: this .nullValue ,
94
- masked: this .masked ,
95
- reverseFill: this .reverseFill ,
96
- prefill: this .prefill ,
97
- precision: this .precision ,
98
- minimumFractionDigits: this .minimumFractionDigits ,
99
- decimal: this .decimal ,
100
- min: this .min ,
101
- max: this .max ,
102
- separator: this .separator ,
103
- prefix: this .prefix ,
104
- suffix: this .suffix
105
- }
96
+
97
+ const change = () => {
98
+ emit (' update:model-value' , emittedValue )
106
99
}
107
- },
108
- methods: {
109
- input(event : Event ) {
110
- const { target } = event as CustomInputEvent
111
- this .maskedValue = target .value
112
- this .unmaskedValue = target .unmaskedValue
113
- this .$emit (' input:model-value' , this .emittedValue )
114
- },
115
- change() {
116
- this .$emit (' update:model-value' , this .emittedValue )
100
+
101
+ return {
102
+ config ,
103
+ maskedValue ,
104
+ input ,
105
+ change
117
106
}
118
107
}
119
108
})
0 commit comments