I need to include in my app some icons that the designer passed me in svg format. I use:
- vue 3.4 (using composition api)
- Vite 5.2
- PrimeVue 4.0
I created a directory src/icons and put inside it my icon as a file:
src/icons/icon-text.svg
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> <g id="Icons"> <path id="Union" fill-rule="evenodd" clip-rule="evenodd" d="M0.383259 0C0.171591 0 0 0.159488 0 0.356227V6.20405C0 6.40078 0.171591 6.56027 0.383259 6.56027H1.65261C1.86428 6.56027 2.03587 6.40078 2.03587 6.20405V1.78968H8.98206V18.2103H5.69523C5.48356 18.2103 5.31197 18.3698 5.31197 18.5665V19.6438C5.31197 19.8405 5.48356 20 5.69523 20H14.2634C14.475 20 14.6466 19.8405 14.6466 19.6438V18.5665C14.6466 18.3698 14.475 18.2103 14.2634 18.2103H11.0041V1.78968H17.9779V6.20405C17.9779 6.40078 18.1495 6.56027 18.3612 6.56027H19.6167C19.8284 6.56027 20 6.40078 20 6.20405V0.356227C20 0.159488 19.8284 0 19.6167 0H0.383259Z" fill="black"/> </g> </svg> I tried several approaches:
- Importing file content as is and use
v-htmlin order to render svg - Importing file as a component (
import TextIcon from '@/icons/icon-text.svg';) and then use it (<TextIcon />) ) - Create a new component Icons.vue in order to import all icons
None of these approaches worked for me, I guess it shouldn't be so complicated, any help please?
BTW, if I directly put the svg code in a component, I do see it.