[Vuejs]-Using v-html in blade foreach loop [Vue warn]: Error compiling template

1👍

Assuming marked to be a method declared in Vue instance, you can quote the interpolated content but first convert all the characters in it to corresponding HTML entities. For example,

<div v-html="marked('{{ htmlentities($entry->content) }}')">

I suggest to write this in the model as a computed property.

class Entry extends Model {
    protected $appends = ['content_html']

    getContentHtmlAttribute() {
        return htmlentities($this->content);
    }
}

Then use the computed field in your template,

<div v-html="marked('{{ $entry->content_html }}')">

Leave a comment