1 Star 20 Fork 1

小磊丶同学/vite_react_init

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
App.jsx 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
import React, { useEffect, useState } from 'react';
import { useRoutes } from 'react-router-dom';
import zhCN from 'antd/lib/locale/zh_CN';
import { StyleProvider, px2remTransformer } from '@ant-design/cssinjs';
import { ConfigProvider } from 'antd';
import { App as AntdApp } from 'antd';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import { setHtmlRem } from './plugins/plugin-set-rem.js';
import routes, { transformRoutes } from './routes/index.jsx';
dayjs.locale('zh-cn');
const App = () => {
const pages = useRoutes(transformRoutes(routes));
const [px2rem, setPx2rem] = useState(
px2remTransformer({
rootValue: 16,
}),
);
// 设置rem执行函数
const handleSetRem = () => {
setHtmlRem();
setPx2rem(px2remTransformer({ rootValue: document.documentElement.style.fontSize.replace('px', '') }));
};
// 改变窗口大小时重新设置单位大小
useEffect(() => {
handleSetRem();
const resizeFun = window.addEventListener('resize', handleSetRem);
return () => {
window.removeEventListener('resize', resizeFun);
};
}, []);
return (
<ConfigProvider
locale={zhCN}
theme={{
cssVar: true,
token: {
colorPrimary: '#00b96b',
borderRadius: 4,
},
}}
>
<AntdApp message={{ maxCount: 1 }} style={{ width: '100%', height: '100%' }}>
<StyleProvider transformers={[px2rem]}>{pages}</StyleProvider>
</AntdApp>
</ConfigProvider>
);
};
export default App;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/whyfail/vite_react_init.git
git@gitee.com:whyfail/vite_react_init.git
whyfail
vite_react_init
vite_react_init
master

搜索帮助