如何显示 props 或 state in alert?

How to display props or state in alert?

如何在提示框中显示道具或状态? 当我们在控制台上打印时如何在警告框中显示它。

 alert('Props',this.props);

Alert 只接受一个参数。如果你想做这样的事情,你应该写:

alert('props' + this.props);

您需要使用JSON.stringify将其转换为字符串。

警报('props: ' + JSON.stringify(this.props));