首页 > 解决方案 > 如何处理错误“找不到图标”

问题描述

我动态创建图标名称,有时会发生库中没有对应的图标。有什么方法可以捕获错误并使用默认图标名称?

标签: reactjsfont-awesomereact-font-awesome

解决方案


您可以使用findIconDefinition以下方式查找图标名称:

// Set params with details of the icon you're looking up depending
// on what variant you're using.
let params = {
   iconName: iconName,
   prefix: prefix
   // other entries as needed
};
if (!findIconDefinition(params)) {
    // Use default icon here.
}

详细信息findIconDefinitionhttps://fontawesome.com/how-to-use/javascript-api/methods/findicondefinition


推荐阅读