Home > Web Front-end > Vue.js > body text

How to wrap lines in vue.js

coldplay.xixi
Release: 2020-11-30 13:56:04
Original
19223 people have browsed it

How to wrap lines in vue.js: Use [v-html] to display, the code is [

data(){return}requestText :""}].

How to wrap lines in vue.js

The operating environment of this tutorial: windows10 system, vue2.9, this article is applicable to all brands of computers.

【Recommended related articles: vue.js

Line wrapping method in vue.js:

Custom text is often encountered on the page. If the text is too long, it needs to be wrapped. In HTML, you can wrap it through the

tag, or you can wrap it through the \n swivel chair character. The following is in javascript and vue. Line breaks

Line breaks in javascript

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

Line breaks in vue

The above line breaks in vue are not It works, 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 treated 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

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How to wrap lines in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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