antd使用ts,List.Item不能使用onclick事件和style属性

<List
        header={<div>list</div>}
        bordered={true}
        dataSource={props.list}
        renderItem={(item, index) => (<List.Item onClick={() => { props.handleItemDelete(index) }}>{item}</List.Item>)}
        style={{ width: '386px', marginTop: '20px' }}
      />

<List中提示

[ts]
不能将类型“{ header: Element; bordered: true; dataSource: any; renderItem: (item: any, index: any) => Element; style: { width: string; marginTop: string; }; }”分配给类型“IntrinsicAttributes & IntrinsicClassAttributes<List> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<ListProps>, "footer" | "header" | "id" | "size" | "className" | ... 8 more ... | "locale"> & Partial<...> & Partial<...>”。
  类型“IntrinsicAttributes & IntrinsicClassAttributes<List> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<ListProps>, "footer" | "header" | "id" | "size" | "className" | ... 8 more ... | "locale"> & Partial<...> & Partial<...>”上不存在属性“style”。 [2322]
(alias) class List
import List

<List.Item中提示

[ts]
不能将类型“{ children: any; onClick: () => void; }”分配给类型“IntrinsicAttributes & IntrinsicClassAttributes<Item> & Readonly<{ children?: ReactNode; }> & Readonly<ListItemProps>”。
  类型“IntrinsicAttributes & IntrinsicClassAttributes<Item> & Readonly<{ children?: ReactNode; }> & Readonly<ListItemProps>”上不存在属性“onClick”。 [2322]
(alias) class List
import List
阅读 11.1k
3 个回答

List只是用于数据的展示。
既然不支持onClick属性,你可以把事件定义在你传给List.Item子元素中。

新手上路,请多包涵

可以绑定onClick,没有提供更多代码就不知道问题出在哪里。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题