Home >Web Front-end >JS Tutorial >Detailed explanation of line breaks in vue and js
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.
var reg=new RegExp("\n","g"), str= res.data.replace(reg,"<br>"); $('.class').html(str);
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;
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>"); $('.class').html(str);Line breaks in vueThe above line breaks in vue do not work Yes, because {{}} in vue displays variables,
<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;
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!