Home > Web Front-end > JS Tutorial > Detailed explanation of line breaks in vue and js

Detailed explanation of line breaks in vue and js

小云云
Release: 2018-03-22 17:28:37
Original
9385 people have browsed it

Custom text is often encountered on the page. If the text is too long, it needs to be wrapped. In HTML, it can be wrapped through tags or through the \n swivel chair character. The following is the wrapping in javascript and vue. Hope it helps everyone.

Line breaks in javascript

var reg=new RegExp("\n","g"),
str= res.data.replace(reg,"<br>");
$(&#39;.class&#39;).html(str);
Copy after login
Copy after login

Line breaks in vue

The above line breaks in vue do not work, because {{}} is displayed in vue is a variable,
will be displayed as a string, \n will be displayed as a space. Therefore, the content inside {{}} will be processed as an ordinary string. If you want to display line breaks, you can use v-html to display it.

<p class="text" v-html="requestText"></p>* 以下requestText是变量*data(){    return{
    requestText:""
    }
}**一下是从服务器获取的动态数据**
 let reg=new RegExp("\n","g"); 
 let str= result.data.replace(reg,"<br>");
 this.requestText=str;
Copy after login
Copy after login

                                                                                                                         ​Line breaks, the following are line breaks in javascript and vue

Line breaks in javascript

var reg=new RegExp("\n","g"),
str= res.data.replace(reg,"<br>");
$(&#39;.class&#39;).html(str);
Copy after login
Copy after login

Line breaks in vue

The above line breaks in vue do not work Yes, because {{}} in vue displays variables,

will be displayed as a string, and \n will be displayed as a space. Therefore, the content inside {{}} will be processed as an ordinary string. If you want to display line breaks, you can use v-html to display it.

<p class="text" v-html="requestText"></p>* 以下requestText是变量*data(){    return{
    requestText:""
    }
}**一下是从服务器获取的动态数据**
 let reg=new RegExp("\n","g"); 
 let str= result.data.replace(reg,"<br>");
 this.requestText=str;
Copy after login
Copy after login

Related recommendations:

CSS controls text wrapping and cropping

php text style implementation code that retains multiple spaces and line wrapping

Detailed explanation of the problem when php handles line breaks

The above is the detailed content of Detailed explanation of line breaks in vue and js. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template