6

I receive inside the object passed in my component a body (actu.body) with html tags inside (mostly p tags) and im wondering how to interpret them for the client side, my code is like that for now :

<template>
  <div>
  <!-- {{ actu }} -->
  <v-parallax
    :src="actu.images[0].url"
    dark
  >
  <v-layout
    align-center
    column
    justify-center
  >
  <h1 class="display-2 font-weight-thin mb-3">{{ actu.headline }}</h1>
    <h4 class="subheading">{{ actu.summarry }}</h4>
  </v-layout>
  </v-parallax>
  <v-card>
    <v-card-text>
      {{ actu.body }}
    </v-card-text>
  </v-card>
  </div>
</template>


<script>
export default {
props: {
actu: {
  type: Object,
  required: true
}

} };

is there a proper way to do that with vue js ?

2 Answers 2

12

have a look at the official guide: https://v2.vuejs.org/v2/guide/syntax.html#Raw-HTML

the trick is the v-html directive

<span v-html="rawHtml"></span>
Sign up to request clarification or add additional context in comments.

2 Comments

when I run npm run lint, warning appears warning 'v-html' directive can lead to XSS attack vue/no-v-html
yes thats right, and this is also documented in the docs from vue. So you should only use this if you can trust the source and never put in there user content.
3

Yes, use v-html.

<v-card-text v-html="actu.body"></v-card-text>

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.