0

I have a Vue.js component which builds the content of an svg element dynamically. For simplicity's sake, say the content is <circle cx="50" cy="50" r="60" />

The component does so by manipulating a data variable named svg:

  data() {
    return {
      svg: '<circle cx="50" cy="50" r="60" />',
      foobar: 'foobar',
    };
  },

I have some specific svg element customizations (i.e. width, height, viewBox) in the parent component. How do I render this out in the template in a "raw" form?

<template>
<svg v-html="svg"></svg>
</template>

will add the svg element which I don't want

1 Answer 1

2

The easiest way is to put the v-html on a standard SVG <g> (group) element:

<template>
  <g v-html="svg"></g>
</template>

This doesn't render the 'raw' form of the html, but the <g> element shouldn't be a problem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.