1

I have an API that is returning, among other things, an SVG image as ASCII text code. So I have that in a value. I am trying to display it as part of my page. It's just giving me a blank image.

This is the JSFiddle of my attempt: https://jsfiddle.net/c0p4ku78/

The essences of the code is effectively this:

<template>
<div id="app">
  <svg>{{circle}}</svg>
</div>
</template>
<script>
export default {
  name: "ImageShower",
  data: () {
    return {
      circle: `<?xml version="1.0" encoding="iso-8859-1"?> ... `
    }
  },
}
</script>

In the real code, circle comes from a web service and is not hard coded into the view component. But it looks more or less as is abbreviated here.

How can I display this SVG as an image?

1 Answer 1

2

You could render it using v-html directive :

<template>
<div id="app">
  <div v-html="circle"></div>
</div>
</template>
<script>
export default {
  name: "ImageShower",
  data: () {
    return {
      circle: `<?xml version="1.0" encoding="iso-8859-1"?> ... `
    }
  },
}
</script>
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.