Iconify for Vue 2 function: replaceIDs

This tutorial is part of Iconify for Vue 2 functions tutorial.

Function replaceIDs() finds IDs in SVG and replaces them with unique random IDs.

This function is meant to be used when you generate <svg> element yourself using data provided by getIcon().


Function has the following parameters:

  • data, string. Icon content.
  • prefix, string | function. Optional prefix for generated IDs. It can be a string or a callback that returns string.

Function returns string containing icon data with IDs replaced.


This is a rather useless example. In real core this function is used when generating SVG code samples in Icon Finder, which is not as simple as this example.

import { replaceIDs, getIcon } from '@iconify/vue2';

// Get icon data
const data = getIcon('carbon:deploy');

// Get content
const body = replaceIDs(data.body);

console.log('Icon content:', body);