import { Button } from "antd"; import React, { useState } from "react"; import styles from "./index.less";

const Index = () => { const [btnList, setBtnList] = useState([ { active: true, id: 1, content: "通用安全基线", }, { active: false, id: 2, content: "共有云安全基线", }, { active: false, id: 3, content: "软件平台安全基线", }, { active: false, id: 4, content: "其他基线", }, ]);

const handleButtonClick = (id) => { const updatedBtnList = btnList.map((item) => { if (item.id === id) { return { ...item, active: true }; } else { return { ...item, active: false }; } }); setBtnList(updatedBtnList); };

return (

已发布基线

{btnList.map((item) => { return ( <Button key={item.id} shape="round" onClick={() => handleButtonClick(item.id)} className={item.active ? styles.activeButton : ""} > {item.content} ); })}
); };

export default Index;

把下面代码改成函数式组件点击对应Button改变active的值:import Button Result Typography Card from antd;import React useState from react;import styles from indexless;import CustomButton from componentsCustomButton;const

原文地址: https://www.cveoy.top/t/topic/iyIE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录