ant-design-vue/components/input-number/demo/formatter.vue

49 lines
987 B
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<docs>
---
order: 0
title:
zh-CN: 格式化展示
en-US: Formatter
---
## zh-CN
通过 `formatter` 格式化数字以展示具有具体含义的数据往往需要配合 `parser` 一起使用
## en-US
Display value within it's situation with `formatter`, and we usually use `parser` at the same time.
</docs>
<template>
<div>
<a-input-number
v-model:value="value1"
:formatter="value => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
:parser="value => value.replace(/\$\s?|(,*)/g, '')"
/>
<a-input-number
v-model:value="value2"
:min="0"
:max="100"
:formatter="value => `${value}%`"
:parser="value => value.replace('%', '')"
/>
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const value1 = ref<number>(1000);
const value2 = ref<number>(100);
return {
value1,
value2,
};
},
});
</script>