feat: refs #7936 limit decimal places
This commit is contained in:
parent
f5f1cdf0ac
commit
070b831392
|
@ -1,13 +1,26 @@
|
|||
<script setup>
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import { ref } from 'vue';
|
||||
import { useAttrs } from 'vue';
|
||||
|
||||
defineProps({
|
||||
step: { type: Number, default: 0.01 },
|
||||
decimalPlaces: { type: Number, default: 2 },
|
||||
});
|
||||
|
||||
const model = defineModel({ type: [Number, String] });
|
||||
const $attrs = useAttrs();
|
||||
const step = ref($attrs.step || 0.01);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VnInput v-bind="$attrs" v-model.number="model" type="number" :step="step" />
|
||||
<VnInput
|
||||
v-bind="$attrs"
|
||||
v-model.number="model"
|
||||
type="number"
|
||||
:step="step"
|
||||
@input="
|
||||
(evt) => {
|
||||
const val = evt.target.value;
|
||||
const [, decimal] = val.split('.');
|
||||
if (val && decimal?.length > decimalPlaces)
|
||||
model = parseFloat(val).toFixed(decimalPlaces);
|
||||
}
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue