Skip to content

Commit 53949b5

Browse files
committed
fix: 动态设置主题颜色 meta 标签
- 在 App 组件中添加 createEffect,动态更新主题颜色 meta 标签 - 移除了 Meta 组件中静态的主题颜色设置
1 parent f0f9ebb commit 53949b5

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/App.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ export function App() {
2525
makeDisableDefaultContextMenuListener();
2626
}
2727
});
28+
// Meta 组件不稳定,所以需要手动更新
29+
createEffect(() => {
30+
let themeColorMeta = document.querySelector<HTMLMetaElement>('meta[name="theme-color"]');
31+
if (!themeColorMeta) {
32+
themeColorMeta = document.createElement('meta');
33+
themeColorMeta.name = 'theme-color';
34+
document.head.appendChild(themeColorMeta);
35+
}
36+
themeColorMeta.content = theme.palette.background.default;
37+
});
2838
}
2939

3040
const currentLocale = createCurrentLocale();
@@ -46,6 +56,7 @@ export function App() {
4656
<Title>{t('app.name')}</Title>
4757
<Meta name="description" content={t('app.description')} />
4858
<Meta name="apple-mobile-web-app-title" content={t('app.name')} />
59+
{/* <Meta name="theme-color" content={theme.palette.background.default} /> */}
4960
</MetaProvider>
5061
<GlobalStyles
5162
styles={{

0 commit comments

Comments
 (0)