前端组件库:别再重复造轮子了

前端组件库:别再重复造轮子了

毒舌时刻

这组件写得跟拼凑似的,一点都不统一。

各位前端同行,咱们今天聊聊前端组件库。别告诉我你还在手动编写所有组件,那感觉就像在没有工具的情况下盖房子——能盖,但效率低得可怜。

为什么你需要组件库

最近看到一个项目,每个组件都要手动编写,样式不统一,维护困难。我就想问:你是在做组件还是在做重复劳动?

反面教材

// 反面教材:手动编写组件 // Button.jsx import React from 'react'; function Button({ children, onClick }) { return ( <button onClick={onClick} style={{ padding: '10px 20px', backgroundColor: '#007bff', color: '#fff', border: 'none', borderRadius: '4px', cursor: 'pointer' }} > {children} </button> ); } export default Button; // Input.jsx import React from 'react'; function Input({ value, onChange, placeholder }) { return ( <input type="text" value={value} onChange={onChange} placeholder={placeholder} style={{ padding: '10px', border: '1px solid #ddd', borderRadius: '4px', width: '100%' }} /> ); } export default Input; // Card.jsx import React from 'react'; function Card({ children }) { return ( <div style={{ padding: '20px', border: '1px solid #ddd', borderRadius: '4px', boxShadow: '0 2px 4px rgba(0,0,0,0.1)' }} > {children} </div> ); } export default Card; 

毒舌点评:这组件编写,就像在重复造轮子,每个组件都要手动编写样式,效率低得可怜。

正确姿势

1. Ant Design

// 正确姿势:Ant Design // 1. 安装依赖 // npm install antd // 2. 基本使用 import React from 'react'; import { Button, Input, Card, Form, Table, Modal, notification } from 'antd'; import 'antd/dist/reset.css'; function App() { const [isModalVisible, setIsModalVisible] = React.useState(false); const showModal = () => { setIsModalVisible(true); }; const handleOk = () => { setIsModalVisible(false); notification.success({ message: '成功', description: '操作成功', }); }; const handleCancel = () => { setIsModalVisible(false); }; const columns = [ { title: '姓名', dataIndex: 'name', key: 'name', }, { title: '年龄', dataIndex: 'age', key: 'age', }, { title: '操作', key: 'action', render: () => ( <Button type="primary">编辑</Button> ), }, ]; const data = [ { key: '1', name: '张三', age: 32, }, { key: '2', name: '李四', age: 42, }, ]; return ( <div style={{ padding: '20px' }}> <Card title="用户管理"> <Button type="primary" onClick={showModal} style={{ marginBottom: '20px' }}> 添加用户 </Button> <Table columns={columns} dataSource={data} /> </Card> <Modal title="添加用户" open={isModalVisible} onOk={handleOk} onCancel={handleCancel} > <Form> <Form.Item label="姓名" name="name" rules={[{ required: true, message: '请输入姓名' }]} > <Input placeholder="请输入姓名" /> </Form.Item> <Form.Item label="年龄" name="age" rules={[{ required: true, message: '请输入年龄' }]} > <Input type="number" placeholder="请输入年龄" /> </Form.Item> </Form> </Modal> </div> ); } export default App; 

2. Material UI

// 正确姿势:Material UI // 1. 安装依赖 // npm install @mui/material @emotion/react @emotion/styled // 2. 基本使用 import React from 'react'; import { Button, TextField, Card, CardContent, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, Modal, Box } from '@mui/material'; function App() { const [isModalVisible, setIsModalVisible] = React.useState(false); const [name, setName] = React.useState(''); const [age, setAge] = React.useState(''); const showModal = () => { setIsModalVisible(true); }; const handleClose = () => { setIsModalVisible(false); }; const handleSubmit = () => { console.log('提交:', { name, age }); setIsModalVisible(false); }; const rows = [ { id: 1, name: '张三', age: 32 }, { id: 2, name: '李四', age: 42 }, ]; return ( <div style={{ padding: '20px' }}> <Card sx={{ mb: 2 }}> <CardContent> <Button variant="contained" color="primary" onClick={showModal} sx={{ mb: 2 }} > 添加用户 </Button> <TableContainer component={Paper}> <Table> <TableHead> <TableRow> <TableCell>姓名</TableCell> <TableCell>年龄</TableCell> <TableCell>操作</TableCell> </TableRow> </TableHead> <TableBody> {rows.map((row) => ( <TableRow key={row.id}> <TableCell>{row.name}</TableCell> <TableCell>{row.age}</TableCell> <TableCell> <Button variant="outlined" color="primary"> 编辑 </Button> </TableCell> </TableRow> ))} </TableBody> </Table> </TableContainer> </CardContent> </Card> <Modal open={isModalVisible} onClose={handleClose} aria-labelledby="modal-modal-title" aria-describedby="modal-modal-description" > <Box sx={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', width: 400, bgcolor: 'background.paper', border: '2px solid #000', boxShadow: 24, p: 4, }}> <h2>添加用户</h2> <TextField label="姓名" fullWidth value={name} onChange={(e) => setName(e.target.value)} /> <TextField label="年龄" type="number" fullWidth value={age} onChange={(e) => setAge(e.target.value)} /> <Box sx={{ mt: 2, display: 'flex', justifyContent: 'flex-end', gap: 1 }}> <Button onClick={handleClose}>取消</Button> <Button variant="contained" color="primary" onClick={handleSubmit}> 提交 </Button> </Box> </Box> </Modal> </div> ); } export default App; 

3. Tailwind CSS + Shadcn UI

// 正确姿势:Tailwind CSS + Shadcn UI // 1. 安装依赖 // npm install -D tailwindcss postcss autoprefixer // npx tailwindcss init -p // npx shadcn@latest init // 2. 配置 Tailwind CSS // tailwind.config.js /** @type {import('tailwindcss').Config} */ export default { content: [ "./index.html", "./src/**/*.{js,ts,jsx,tsx}", ], theme: { extend: {}, }, plugins: [], } // 3. 基本使用 import React from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Table, TableBody, TableCell, TableHead, TableRow } from '@/components/ui/table'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; import { Label } from '@/components/ui/label'; function App() { const rows = [ { id: 1, name: '张三', age: 32 }, { id: 2, name: '李四', age: 42 }, ]; return ( <div className="p-4"> <Card className="mb-4"> <CardHeader> <CardTitle>用户管理</CardTitle> </CardHeader> <CardContent> <Dialog> <DialogTrigger asChild> <Button className="mb-4">添加用户</Button> </DialogTrigger> <DialogContent className="sm:max-w-md"> <DialogHeader> <DialogTitle>添加用户</DialogTitle> </DialogHeader> <div className="grid gap-4 py-4"> <div className="grid gap-2"> <Label htmlFor="name">姓名</Label> <Input placeholder="请输入姓名" /> </div> <div className="grid gap-2"> <Label htmlFor="age">年龄</Label> <Input type="number" placeholder="请输入年龄" /> </div> </div> <div className="flex justify-end gap-2"> <Button variant="secondary">取消</Button> <Button>提交</Button> </div> </DialogContent> </Dialog> <div className="overflow-auto"> <Table> <TableHead> <TableRow> <TableCell>姓名</TableCell> <TableCell>年龄</TableCell> <TableCell>操作</TableCell> </TableRow> </TableHead> <TableBody> {rows.map((row) => ( <TableRow key={row.id}> <TableCell>{row.name}</TableCell> <TableCell>{row.age}</TableCell> <TableCell> <Button variant="secondary">编辑</Button> </TableCell> </TableRow> ))} </TableBody> </Table> </div> </CardContent> </Card> </div> ); } export default App; 

毒舌点评:这才叫前端组件库,统一的样式,丰富的组件,开发效率高,再也不用担心重复造轮子的问题了。

Read more

【FPGA】Quartus Prime Lite 23.1 最新版 安装教程 ModelSim_18.1 下载安装 + 联调仿真教程 + 详细安装教程 2025最新

【FPGA】Quartus Prime Lite 23.1 最新版 安装教程 ModelSim_18.1 下载安装 + 联调仿真教程 + 详细安装教程 2025最新

前言         本文章基于截至2025年 Quartus_Prime_Lite的最新版 23.1 版本,详细的,一步一步的教你怎么安装,每一步都教你怎么做,按照流程绝对能安装成功。创作不易希望大家看完后点个赞支持创作,谢谢大家啦! 目录  软件下载地址 Quartus Prime Lite 23.1 ModelSim-Intel® FPGA 标准版软件版本 18.1 若不想在官网下载或官网下载速度太慢 点个关注+收藏可以免费用下面的百度链接进行下载  两个软件的安装包都在里面。如果使用百度链接下载则可跳过两个软件的下载流程,直接看安装流程。 一、Quartus Prime Lite 23.1 下载以及安装流程 1.1 Quartus Prime Lite 23.1 官方网站下载流程 第一步 打开上方链接到达如下界面 确保软件名称和版本如下图

教你一步步在 服务器/本地(Linux/Windows) 部署鸣潮QQ机器人,并将其接入大语言模型,实现通过机器人进行库街区签到、练度查询、攻略查询等功能 (1)

准备工作 一台轻量级服务器/ 本地windows/linux能够在服务器/本地 科学上网 环境部署 笔者所演示的环境为阿里云服务器(2核CPU,2GIB内存,40GIB系统盘),操作系统为 Ubuntu 24.04. 确保已成功安装Python环境(版本须>3.8, 建议>=3.12,不建议>=3.13) 确保已成功安装git 如果你没有安装git且的系统是ubuntu,安装git只需要输入 如果系统为Windows,则自行前往 🔗官网 下载安装包安装即可 创建虚拟环境 从 Python 3.11 开始,Debian 和 Ubuntu 默认启用了 "Externally-Managed-Environment"(外部管理环境)保护机制,

FPGA Transformer加速完全指南:从模型优化到硬件实现(附实战案例)

🚀 FPGA Transformer加速完全指南:从模型优化到硬件实现(附实战案例) 📚 目录导航 文章目录 * 🚀 FPGA Transformer加速完全指南:从模型优化到硬件实现(附实战案例) * 📚 目录导航 * 概述 * 第一部分:Transformer基础与FPGA加速价值定位 * 1.1 Transformer架构概览 * 1.1.1 Transformer的基本结构 * 1.1.2 Transformer的关键特性 * 1.1.3 常见的Transformer变体 * 1.2 Transformer推理的挑战 * 1.2.1 计算复杂度分析 * 1.2.2 内存访问瓶颈 * 1.2.3 非线性操作的挑战 * 1.2.4 推理延迟分析 * 1.3

一套非常专业且完整的智能梯控系统设计方案,涵盖了跨品牌电梯群控、VIP专属乘梯、机器人乘梯接口、高峰运力优化等核心模块。从技术架构到硬件选型、施工流程都考虑得相当周密,具备了实际落地的可操作性

一套非常专业且完整的智能梯控系统设计方案,涵盖了跨品牌电梯群控、VIP专属乘梯、机器人乘梯接口、高峰运力优化等核心模块。从技术架构到硬件选型、施工流程都考虑得相当周密,具备了实际落地的可操作性

前言:多奥的方案抓住了智能梯控的本质:在不影响电梯原有安全逻辑的前提下,通过外围接入方式实现智能调度和权限管控。这正是行业当前的主流技术路线。 一、方案核心优势分析 1. 技术架构的先进性 你的架构设计采用了中央控制单元(DAIC-TK-PC)+ 群控器(DAIC-TK-QK)+ 权限管理模块的分布式架构,这种分层设计的优势在于: * 独立性强:与电梯原PLC完全隔离,采用无源干接点方式对接,确保电梯原有安全回路不受影响 * 扩展性好:支持多种识别方式(IC卡/二维码/人脸),可灵活对接第三方系统(机器人、AGV、门禁等) * 安全可靠:消防联动、故障自检脱离等机制完善,符合特种设备安全规范 2. 跨品牌兼容的创新突破 这正是当前行业的痛点。你提到的通过外围接线安装、免破线接入的方式,实现不同品牌电梯(如三菱、迅达、奥的斯等)的统一群控,这正是行业前沿的技术路线。 根据我掌握的最新信息,这类跨品牌群控方案已在实际项目中验证: * 运力提升40-50% :通过智能调度避免多梯空跑空停 * 能耗降低约30% :减少无