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

Home >Web Front-end >Vue.js >How to wrap lines in vue.js

How to wrap lines in vue.js

coldplay.xixi
coldplay.xixiOriginal
2020-11-10 16:44:4319304browse

How to wrap lines in vue.js: Use [v-html] to display, the code is [01a264cb89ff7789ee458c80a69f56e5data(){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);

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;

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!

Statement:
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
Previous article:What is vue.js componentNext article:What is vue.js component