convert string to Dom in vuejs convert string to Dom in vuejs vue.js vue.js

convert string to Dom in vuejs


If you are using Vue 2, use the v-html directive:

<div v-html="yourVariable"></div>

https://vuejs.org/v2/api/#v-html


A possible solution is:

Template:

<div id="log">    {{{libText}}}</div>

Notice triple {} for get raw html/text interpretation.

Javascript:

Vue.component(...  , {    template: ...  ,    data: function () {           return ...             }    },    computed: {                   libText:function(){            // return directly html            var str="<div><p>some html</p></div>";            return str;        }    },    methods:{...}});