I have variable array of objects, one of which is contains element p in the string. And I want to append to element div.profile-description
But the result is vue js return raw html to div.profile-description
I want to p in the string become element in html
JavaScript
x
11
11
1
var interviewees = [
2
{name: 'Anthony', profession: 'Developer', description: '<p>Now he works in one</p><p>very famous company</p>'},
3
{name: 'Erick', profession: 'Gamer', description: '<p>He is focusing on playing</p><p>the heroes of the storm game</p>'}
4
];
5
6
var setDescription = new Vue({
7
el: '.profile-description',
8
data: {
9
interviewee_description: interviewees[1].description
10
}
11
});
JavaScript
1
4
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.0/vue.js"></script>
2
<div class="profile-description">
3
{{ interviewee_description }}
4
</div>
Advertisement
Answer
You need use the v-html
directive:
JavaScript
1
2
1
<div v-html="interviewee_description" class="profile-description"></div>
2
Alert:
Dynamically rendering arbitrary HTML on your website can be very dangerous because it can easily lead to XSS vulnerabilities. Only use HTML interpolation on trusted content and never on user-provided content. https://v2.vuejs.org/v2/guide/syntax.html#Raw-HTML