【问题标题】:Intl.NumberFormat.prototype.formatToParts support for Safari older version from 13Intl.NumberFormat.prototype.formatToParts 支持 Safari 13 起的旧版本
【发布时间】:2021-12-03 09:40:33
【问题描述】:

我的应用程序出现错误,**formaTtoParts** 未定义

TypeError: Intl.NumberFormat(t,{minimumFractionDigits:2}).formatToParts is not a
function. (In 'Intl.NumberFormat(t,{minimumFractionDigits:2}).formatToParts(ri(e))',
 'Intl.NumberFormat(t,{minimumFractionDigits:2}).formatToParts' is undefined)
browser.name:
Mobile Safari UI/WKWebView

device:
iPhone

interface_type:
exception

os:
iOS 12.5.5

是否有可能找到一个 polyfill 来支持从 13 开始的以前版本的 Safar 的替代解决方案???

【问题讨论】:

  • 查看documentation at MDN。有关于支持的浏览器/环境的详细信息,包括 formatToParts 和 polyfill 的链接。

标签: javascript number-formatting


【解决方案1】:

https://formatjs.io/docs/react-intl/components#formattednumberparts

React Intl has a set of React components that provide a declarative way to
 setup an i18n context and format dates, numbers, and strings for display in 
a web UI. The components render React elements by building on React Intl's imperative API.

当不支持 Intl.NumberFormat.prototype.formatToParts 时,这可能会对我们的设备有所帮助

这里是检查更多实施细节的文件: FormatNumericToParts.ts

此外,@formatjs 也可以用作 polyfill

import '@formatjs/intl-numberformat/polyfill'
import '@formatjs/intl-numberformat/locale-data/en' // locale-data for en

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-29
    • 2014-06-15
    • 1970-01-01
    • 1970-01-01
    • 2022-12-16
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    相关资源
    最近更新 更多