99 @input =" input"
1010 />
1111</template >
12-
1312<script lang="ts">
14- import { defineComponent } from ' vue'
13+ import { defineComponent , ref , computed } from ' vue'
1514import { cloneDeep , CustomInputEvent , Input } from ' ./core'
1615import directive from ' ./directive'
1716import defaultOptions from ' ./options'
@@ -30,7 +29,8 @@ export default defineComponent({
3029 },
3130 nullValue: {
3231 type: [Number , String ],
33- default : () => options .nullValue
32+ required: false ,
33+ default: options .nullValue
3434 },
3535 masked: {
3636 type: Boolean ,
@@ -78,42 +78,31 @@ export default defineComponent({
7878 }
7979 },
8080 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 )
8595 }
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 )
10699 }
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
117106 }
118107 }
119108})
0 commit comments