javascript - React this.props 在状态事件中未定义?
问题描述
我正在尝试在状态下使用值props
,但我收到未定义的错误,并且值也未显示在控制台日志上。这是我所做的代码:dataPointSelection
apexchart
this.props
constructor(props) {
super(props);
const { t, too, fromm } = this.props;
console.log("Upper" + this.props.fromm);
this.state = {
...props,
options: {
chart: {
id: "Speeding",
events: {
dataPointSelection: function(event, chartContext, opts) {
switch (opts.w.config.xaxis.categories[opts.dataPointIndex]) {
case "0-10":
window.open(
window.location.origin +
`/overspeeding/10/0/${
this.props.too ? `${this.props.too}` : `${cc}`
}/${
this.props.fromm ? `${this.props.fromm}` : "2016-01-04"
}` // in this line i am getting error
);
如何解决此错误和事件中的用户道具值?
解决方案
您通常不需要在构造函数中的道具后面使用它。只用道具试试
推荐阅读
- asp.net-core - asp.net 核心 mvc 。有两个(索引)方法同名错误
- vim - `:!mutt -f some.mbox` 适用于 Vim 8.1,但在 NeoVim 0.3.1 中返回 `No recipients specified`
- python - 自定义解释器提示后python解释器中的错误缩进
- sql - SQL Server:忽略 AVG NULL 值
- list - 没有为类 'Map<>' 定义 getter 为 Map 列出 getter
- android - 找不到符号类数据绑定 impl
- jpa - 如何使用 EclipseLink 从 JPQL 查询返回键/值对映射列表?
- python - 匹配两个节点并保持其他各自节点之间的路径networkx
- javascript - 在 JavaScript 中按名称而不是 id 单击元素
- moodle - 拥有 30000 个用户的 Moodle 的服务器硬件