How to solve html rendering with VUE?

3

I'm doing a test with the wordpress rest-api with vue 2.x, and one of the returned attributes is as follows:

"content":  {
    "rendered": "<P>Bem-vindo ao WordPress. Esse é o seu primeiro post. Edite-o ou exclua-o, e então comece a escrever!</P>\n"
},

Then on my page the html "p" is displayed. I tried to resolve with {{{ }}} but the version recognizes more in this way. And with v-html also gives error.

    
asked by anonymous 31.03.2017 / 18:34

1 answer

1

In Vue.js 2 you have to use the v-html that receives the variable that has the HTML you want to use:

var data = {
    "content": {
        "rendered": "<P>Bem-vindo ao WordPress. Esse é o seu primeiro post. Edite-o ou exclua-o, e então comece a escrever!</P>\n"
    }
};

var demo = new Vue({
    el: '#demo',
    data: data
});
<script src="http://vuejs.org/js/vue.min.js"></script><divid="demo">
    <div v-html="content.rendered"></div>
</div>

jsFiddle: link

    
31.03.2017 / 18:40