Vue 3-货币输入过滤器

问题描述

没有人知道一个将数字输入转换为货币格式并可以应用于Vue 3的库,因为大多数人使用的是Vue 3版本当前不支持的过滤器?

解决方法

您可以结合使用计算属性和Intl.NumberFormat(或某些货币npm软件包)。

<template>
    <div>{{costCurrency}}</div>
</template>

<script>
const formatter = new Intl.NumberFormat('en-US',{style: 'currency',currency: 'USD'})

export default {
    props: {
        cost: Number
    },computed: {
        costCurrency() {
            return formatter.format(cost)
        }
    }
}
</script>

,

vue-currency-input 支持 Vue 3