谷歌素材图标加载缓慢,从文本到图标闪烁

问题描述 投票:0回答:3
reactjs material-design
3个回答
1
投票
在您的

src 文件夹中创建一个名为 preload.js 的文件。

document.fonts.load('10pt "Material Icons"').then(function () { console.log('Material Icons font has been preloaded.'); });

index.html 中的 head 部分末尾添加以下脚本标签

<script defer src="%PUBLIC_URL%/preload.js"></script>
React 组件中的用户像这样

import Icon from '@material-ui/core/Icon'; function MyComponent() { return <Icon>home</Icon>; }
希望它有效


0
投票
只需使用带有链接标记的“预加载”:

<link rel="preload" href="./material-symbols-outlined.woff2" as="font" type="font/woff2" crossorigin>
    

-1
投票
来自

Google JS 转换失败时如何防止素材图标文本显示?:

你可以使用

font-display: block;

,只需将此CSS添加到你的HTML头中:

<style> @font-face { font-family: 'Material Icons'; font-display: block; } </style>
了解更多信息

字体显示

© www.soinside.com 2019 - 2024. All rights reserved.