动态切换全局配置的方法是不是和Plugin-Model有冲突? #12287
-
相关依赖{
"dependencies": {
"antd": "^5.15.1",
"antd-style": "^3.6.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet-async": "^1.3.0",
},
"devDependencies": {
"@ant-design/pro-cli": "^3.3.0",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"@types/react-helmet": "^6.1.11",
"@umijs/fabric": "^2.14.1",
"@umijs/lint": "^4.1.1",
"@umijs/max": "^4.1.9",
}
} 调用方法 const changeTheme = () => {
const { themeMode, antdToken } = getThemeToken();
const targetThemeMode = themeMode === 'dark' ? 'light' : 'dark';
// 将变量写入localStorage
setThemeMode(targetThemeMode);
const algorithm = targetThemeMode === 'light' ? [defaultAlgorithm] : [darkAlgorithm];
const antdTheme: ThemeConfig = { algorithm };
if (antdToken) {
antdTheme.token = antdToken;
}
setAntdConfig({ theme: antdTheme }); 报错信息 |
Beta Was this translation helpful? Give feedback.
Answered by
fz6m
May 11, 2024
Replies: 2 comments 11 replies
This comment has been hidden.
This comment has been hidden.
-
这个问题知道为什么了,详见 #12406 。 在 PR 没修复并发布新版本之前,只要自己给 antd 的配置加个空 // .umirc.ts
antd: { configProvider: { theme: {} } } 这里为空对象不会影响什么,antd 源码里如果不配置 theme ,默认也会用空对象。 之前发过的那个项目级插件写文件的解法就不要用了,太 hack 了。 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
先这样吧,在项目根目录创建一个
plugin.ts
项目级插件: