Just like the title.
Data returned by the background:
Data displayed in the interface document:
Data from the console on chrome:
(I randomly printed these two pieces of data, just to show that there are line breaks in the background)
The final display
is a one-line display without a line break effect and requires front-end processing
I first check whether it contains a newline character
for (let i = 0; i < response.data.Data.length; i ) {
if (response.data.Data[i].content.indexOf('\n') >= 0) {
console.log(i)
}
}
The data in the printed index does not have a newline character, which is inconsistent.
Is this correct? Or do I need to change the conditions to judge?
Please give me some advice~
I don’t understand why I wrote this loop to traverse. The result returned to you is response.data.content. You can use regular expressions to do it
You have console.log ↵, of course you have to write indexOf('↵')
Problem Solved
The original tag that wrapped the returned content was <p>, but later I roughly changed it to <pre>. The h5 tag
can be displayed in new lines
But there is a problem. If other content without line breaks exceeds the width, It will exceed the display and will not wrap automatically
Added css control at the end
pre{
white-space: pre-wrap;
word-wrap: break-word;
}
It’s solved