0

I try to render some html text loaded in a json file.

the textstring holds an class="" css style

"example": word 1<br><span class=\"main-color\">word 2</span> word 3"

the vuejs part looks like this:

<p v-html="example">  </p>

the scoped css:

.main-color  {
  color: #ff00ff;
}

the html code looks as expected in debugger, but the text was not rendered! why?

1 Answer 1

1

You are missing a " at the start of the variable

This works

<script setup>
import { ref } from 'vue'
const example = ref("word 1<br><span class=\"main-color\">word 2</span> word 3")
</script>

<template>
<p v-html="example">  </p>
</template>

<style>
.main-color  {
  color: #ff00ff;
}
</style>
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.