当前位置: 首页 > article >正文

react项目引入ant-design

当前react版本为:

1、安装antd

npm install antd --save

不需要安装babel-plugin-import,否则会报各种问题

2、引入Ant Design 样式

为了确保 Ant Design 样式在页面中生效,你需要在 _app.js 文件中全局引入样式。

当前项目用的Next.js。Next.js 使用 _app.js 来定制全局的应用布局和样式。你需要在 pages/_app.js 中引入 Ant Design 的样式文件。

// pages/_app.js
import 'antd/dist/reset.css';  // 引入 Ant Design 样式
import '../styles/globals.css'; // 如果你有自定义的全局样式文件
import { AppProps } from 'next/app';

function MyApp({ Component, pageProps }: AppProps) {
  return <Component {...pageProps} />;
}

export default MyApp;

3、引入 Ant Design 组件 

在任意 React 页面或组件中使用 Ant Design 组件时,直接按需引入。比如在 pages/index.js 中,你可以引入一个按钮组件:

import { Button } from 'antd';

export default function Home() {
  return (
    <div>
      <h1>Welcome to Next.js with Ant Design</h1>
      <Button type="primary">Primary Button</Button>
    </div>
  );
}

记录一下


http://www.kler.cn/news/337313.html

相关文章:

  • ​牧​原​二​面​
  • 仿RabbitMQ实现消息队列客户端
  • 【VUE】Vue中template模版编译原理
  • javascript中原型链(__proto__)与原型(prototype)
  • numpy np.stack 介绍
  • IL2CPP和Mono的区别
  • solidity中的函数详解
  • 73.【C语言】C/C++的内存区域划分
  • [单master节点k8s部署]31.ceph分布式存储(二)
  • 医院管理新思维:Spring Boot技术应用
  • Maven 高级之分模块设计与继承、聚合
  • springboot中配置优先级
  • idea2023-快速搭建一个本地tomcat的javaWeb项目(从0到1保姆教学)
  • Ubuntu 中 Redis ,MySQL 基本使用
  • PostgreSQL技术内幕13:PostgreSQL通讯协议
  • LLM大模型学习总结
  • 基于SpringBoot+Vue的宠物店管理系统
  • Qt - ui界面点击加载一段时间后闪退
  • TryHackMe 第7天 | Web Fundamentals (二)
  • POST注入通过sqli-labs靶场less-11