In vue, the / n line break is not recognized in the tag, looking for a solution

the data obtained by textarea in vue is passed to the backend. When I get the details, I use the API to get the data I passed in earlier.
but the data I got is put in the tag, the / n newline character is not recognized, and it is still displayed in plain text

.

Printing to the console is normal with line feeds, but it is not available on the page. The effect is shown in figure

.

clipboard.png

v-html


console.log(data.job_description)

clipboard.png

they all change lines normally, so ask for advice on why.

Oct.21,2021

your /\\ n/gm rule represents the global multiline matching string \ n
\ represents escape characters in the rule.
\ n represents a carriage return line feed
\ n represents a string\ n

correct should be as follows

data.job_description.replace(/\n/gm,"<br/>")

just change the rule;

this.text = data.job_description.replace(/\n/g,"<br/>");

I have recently encountered the same problem and found a solution that can be solved through css

the first add style

<p style="white-space: pre-wrap;" v-html="content" >

the second way to add pre tags

<p v-html="content">

original link


you don't render and click the dom element to see if the br tag replacement failed to

var reg= / [n] / try to write


this.text = data.job_description.replace (/\ nUniGM, "< br/ >")
console.log (this.text)
output this.text! Data.job_description is unchanged

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b40683-41550.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b40683-41550.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?