其他分享
首页 > 其他分享> > React点击事件传参方法

React点击事件传参方法

作者:互联网

推荐如下方法:

import React from 'react';
import './CommentList.css'

class CommentList extends React.Component {
  constructor(props) {
    super(props)
  }
  handleDeleteComment = (index) => {
    console.log(index,"传参成功")
} render() { const { comments } = this.props return ( <div> <label>评论列表</label> <ul> { comments.map((comment, index) => <li key={index}> {comment} <button key={index} onClick={this.handleDeleteComment.bind(this, index)} > 删除 </button> </li> ) } </ul> </div> ) } } export default CommentList;

 

      console.log(index, "传参成功")

标签:传参,CommentList,index,comment,React,点击,props
来源: https://www.cnblogs.com/JustSearchIt/p/14368166.html