当我尝试parseInt()时,它说:
_this2.state.grade.parseInt不是一个函数
代码:
this.state = {grade: "1"}
let grade = this.state.grade.parseInt()这个功能不适用于React本机吗?如果是这样,我如何将其转换为int?
发布于 2016-11-27 20:57:37
尝试:
Number.parseInt(this.state.grade, 10)
// the 2nd argument is the base mathematical
// system to use for parsing and should
// always be passed to avoid confusion and
// ensure predictable behaviour发布于 2020-04-15 17:28:24
parseInt是一个全球功能,作为ECMAScript 2015的一部分,可能是不可用的。
另一种用途是:
Number.parseInt(值,基数)
base很重要,因为它会产生不同的值:
十进制
Number.parseInt( '011', 8)
-> 9十进制
Number.parseInt( '011', 10)
->11Hexa十进
Number.parseInt( '011', 16)
->17https://stackoverflow.com/questions/40833360
复制相似问题