【问题标题】:Vue 3 - currency input filter [closed]Vue 3 - 货币输入过滤器 [关闭]
【发布时间】:2020-09-21 10:14:25
【问题描述】:

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

【问题讨论】:

  • Vue 3 刚刚发布,许多库正在等待更新。你动作有点快。

标签: vue.js currency-formatting vuejs3


【解决方案1】:

您可以使用计算属性和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>

【讨论】:

    【解决方案2】:

    vue-currency-input 支持 Vue 3

    【讨论】:

    • 你能描述一下如何吗?初始化看起来像 Vue 2。
    猜你喜欢
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    • 1970-01-01
    • 2014-08-01
    相关资源
    最近更新 更多