Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lars-Janssen's avatar

Vue.js 1.0 show line breaks.

Hi,

I know in blade you can show line breaks like this:

{!! nl2br(e($words)) !!}

But should I do this with vue.js? nl2br is obviously not working here!

0 likes
2 replies
briedis's avatar

My solution:

 <p v-for="(line, index) in commentLines" :key="'line-' + index" class="mb-2">
                    {{ line }}
 </p>

commentLines(): string[] {
            if (!this.activity.comment) {
                return [];
            }

            let lines = this.activity.comment.split('\n');
            lines = lines.map((l) => l.trim());

            return lines;
},

Please or to participate in this conversation.