若依版本:RuoYi-Vue

标签:<svg-icon :icon-class="getClass(scope.row.ext)"></svg-icon>

<svg-icon :icon-class="getClass(scope.row.ext)"></svg-icon>

 <script>块中引入import svgIcons from '@/views/components/icons/svg-icons'

import svgIcons from '@/views/components/icons/svg-icons'
methods方法:
getClass(name){
  if (svgIcons.includes(name)) {
    return name;
  } else {
    return "temp";
  }
},
//判断图标是否存在,不存在是显示默认图标
 getClass(name){
   if (svgIcons.includes(name)) {
     return name;
    } else {
      return "temp";
   }
 },

这个方法比较笨重,因为import svgIcons from '@/views/components/icons/svg-icons'会把所有的svg图标都加载进来。

如果你有更好的方法评论区探讨下。

Logo

快速构建 Web 应用程序

更多推荐