如何处理错误 "Could not find icon"

How to handle the error "Could not find icon"

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

您可以使用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.
}

findIconDefinition 的详细信息位于 https://fontawesome.com/how-to-use/javascript-api/methods/findicondefinition