Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get line breaks with Javascript and VUE

In a response from an API I get a plain text that contains line breaks in this way:

"plain_text": "INFORMACION DEL PRODUCTO:\n\nProducto:

How can I use these line breaks (\n\n) when printing on WEB page with Javascript (I'm using VUE) ?

Since it only passes the text without the line breaks.

I add image of how it prints with VUE but in the inspector if it appears with the line breaks.

text

like image 700
OscarDev Avatar asked Nov 20 '25 11:11

OscarDev


1 Answers

Use the CSS white-space property...

const res = {"plain_text": "\t\t\t\tINFORMACION DEL PRODUCTO:\n\nProducto:"}
new Vue({
  el: '#app',
  data: { res }
})
.pre-formatted {
  white-space: pre-wrap; /* 👈 this is the important part */
  border: 1px dotted;
  padding: 1rem;
}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<div id="app">
  <p class="pre-formatted">{{res.plain_text}}</p>
</div>
like image 185
Phil Avatar answered Nov 22 '25 01:11

Phil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!