您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

react antd没有样式怎么办

2026/1/28 19:58:54发布18次查看
react antd没有样式的解决办法:1、在项目最外层组件引入antd样式包,方式如“@import '~antd/dist/antd.css';”;2、在webpack配置中引入“ ['import', { libraryname: 'antd', style: 'css' }],”。
本教程操作环境:windows10系统、react18.0.0版、dell g3电脑。
react antd没有样式怎么办?
react项目引入antd组件没有样式的问题
明显是antd的样式文件没有引入进来,有两种方式解决:
1.在项目最外层组件引入antd样式包
如在app.css中最上面加
@import '~antd/dist/antd.css';
2.webpack配置引入
module.exports = { entry: { index: path.join(srcpath, 'index.js'), }, module: { rules: [ // babel-loader { test: /\.(js|jsx)$/, loader: ['babel-loader?cachedirectory'],// 开启缓存 include: srcpath, // exclude: /node_modules/ loader: require.resolve('babel-loader'), options: { plugins: [ // 引入样式为 css // style为true 则默认引入less ['import', { libraryname: 'antd', style: 'css' }], ] } } ] }, plugins: [ new htmlwebpackplugin({ template: path.join(srcpath, 'index.html'), filename: 'index.html' }) ]}
推荐学习:《react视频教程》
以上就是react antd没有样式怎么办的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product