import React from "react";
import { Math } from "core-js";
const Person = () => {
return (
<p>
Hello my name chetan and i am {Math.floor(Math.random() * 30)} year old
</p>
);
};
export default Person;
请参考上面的代码。我一直试图显示动态值,但出现以下错误:
TypeError: core_js__WEBPACK_IMPORTED_MODULE_1__.Math.random is not a function
答案 0 :(得分:0)
您不需要导入包core.js,可以使用javascript的Default Math函数,如下所示:
import React from "react";
const Person = () => {
return (
<p>
Hello my name chetan and i am {Math.floor(Math.random() * 30)} year old
</p>
);
};
export default Person;