【发布时间】:2020-07-03 05:09:31
【问题描述】:
我需要自定义 Ant Design 的 Input Number 字段。货币字段的格式为(货币) 例如:R $ 9.800,99。
我使用了 Intl,但 NaN 正在返回。如何解决此错误?
相关链接:
点击:Here
沙盒代码:https://codesandbox.io/s/friendly-hamilton-8pwvi
const MyInput = () => {
const handleChange = event => {
console.log(event);
};
return (
<div>
<InputNumber
name="topText"
style={{
width: 400,
marginRight: "1rem"
}}
formatter={value => new Intl.NumberFormat("pt-BR", {
style: "currency",
currency: "BRL"
}).format(value)
}
onChange={handleChange}
/>
</div>
);
};
const App = () => {
return (
<div className="contain-all">
<MyInput />
</div>
);
};
ReactDOM.render(<App />, document.getElementById("root"));
【问题讨论】:
-
您能否将您的代码发布为文本而不是图像?谢谢!
-
看起来不错,好像传给这个组件的值是空的
-
在操作前不需要将值解析为数字吗?
-
@norbitrial 我添加了沙盒链接。谢谢
标签: javascript html reactjs