Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何恢复Ant设计的图标类型?_Reactjs_Antd - Fatal编程技术网

Reactjs 如何恢复Ant设计的图标类型?

Reactjs 如何恢复Ant设计的图标类型?,reactjs,antd,Reactjs,Antd,我使用一个图标蚂蚁设计,我想恢复我的图标类型,如果她被点击,我可以用它来改变颜色。但是类型没有定义 <Icon type="highlight" onClick={(() =>this.setState({ iconSelected: this.props.type,}),

我使用一个图标蚂蚁设计,我想恢复我的图标类型,如果她被点击,我可以用它来改变颜色。但是类型没有定义

<Icon                                
     type="highlight"                                
     onClick={(() =>this.setState({ iconSelected: this.props.type,}),                                    
          () => console.log(this.props.type))
     }

     style={{height: 50, width: 50, fontSize: 20, color: iconSelected == this.props.type ? "#1890ff" : "grey"}}
/>
this.setState({iconSelected:this.props.type,}),
()=>console.log(this.props.type))
}
样式={{高度:50,宽度:50,字体大小:20,颜色:iconSelected==this.props.type?#1890ff:“灰色”}
/>

在您的单击处理程序中,
不涉及图标本身。您要访问的是需要作为参数传递给处理程序函数的事件对象。然后,您可以访问事件的
目标
,该目标是图标本身的DOM节点,它有一个
数据图标
属性,包含可以使用普通DOM方法访问的图标名称:

<Icon type="mail" onClick={(e) => console.log(e.target.getAttribute('data-icon'))}/>
console.log(e.target.getAttribute('data-icon'))}/>

这将记录图标名称,但您可以使用它执行任何操作。

干杯,乐意帮助!但是现在,我不知道如何检查图标的类型是否是为颜色选择的?(在样式中,因为类型未定义)