javascript - How to determine if the string returned by the background contains a newline?
某草草
某草草 2017-05-19 10:38:15
0
3
1021

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~

某草草
某草草

reply all(3)
習慣沉默

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

/\n/.test(response.data.content)
小葫芦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template