Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color值不生效 #86

Open
xiumubai opened this issue Mar 15, 2023 · 3 comments
Open

color值不生效 #86

xiumubai opened this issue Mar 15, 2023 · 3 comments

Comments

@xiumubai
Copy link

<template>
  <i :class="['el-icon', spin && 'svg-icon-spin']" :style="getStyle">
    <svg aria-hidden="true">
      <use :xlink:href="symbolId" :fill="color" />
    </svg>
  </i>
</template>

<script setup lang="ts" name="SvgIcon">
import { computed } from 'vue'
import type { CSSProperties } from 'vue'
const props = defineProps({
  prefix: {
    type: String,
    default: 'icon',
  },
  name: {
    type: String,
    required: true,
  },
  color: {
    type: String,
    default: '#ffffff',
  },
  size: {
    type: [Number, String],
    default: 20,
  },
  spin: {
    type: Boolean,
    default: false,
  },
})

const symbolId = computed(() => `#${props.prefix}-${props.name}`)
const getStyle = computed((): CSSProperties => {
  const { size } = props
  let s = `${size}`
  s = `${s.replace('px', '')}px`
  return {
    fontSize: s,
  }
})
</script>

<style scoped lang="scss">
.el-icon {
  --color: inherit;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
  font-size: inherit;
  line-height: 1em;
  color: var(--color);
  fill: currentColor;

  svg {
    width: 1em;
    height: 1em;
  }
}

.svg-icon-spin {
  animation: circle 1.5s infinite linear;
}

/* 旋转动画 */
@keyframes circle {
  0% {
    transform: rotate(0);
  }

  100% {
    transform: rotate(360deg);
  }
}
</style>

@caowen
Copy link

caowen commented Jul 12, 2023

When I encountered the same problem as you, how did you solve it?

@edk24
Copy link

edk24 commented Aug 15, 2023

vue3

vite.config.ts / js

add code

createSvgIconsPlugin({
      // 指定需要缓存的图标文件夹
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      // 指定symbolId格式,这里需要与组件找那个的 symbolId 对应
      symbolId: 'icon-[dir]-[name]',

      /**
       * custom dom id
       * @default: __svg__icons__dom__
       */
      customDomId: '__svg__icons__dom__',

+      svgoOptions: {
+        full: true,
+        plugins: [
+         {
+           name: "removeAttrs",
+           params: {
+              attrs: "fill"
+            }
+          }
+        ]
+      },
    }),

batch remove fill attr

洋文不好, 加这个配置就可以了, 删除 fill attr 就可以了, 参考 #70

@cMing1997
Copy link

j加上这个没用的话,可以将包替换成 @digitalacorn/vite-plugin-svg-icons
配置vite.config.ts时,在该插件的配置项中提供了选项
image
replaceStrokeWithCurrentColor
问题在于
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants