我们一般是通过正则表达式配合v-html把接口给的回车换行符改成换行标签,今天给大家看一种通过css样式来实现这一效果的例子。
text.replace(/([.\n\r]+)/g, '<br/>')"
使用v-html
<div style="margin-top: 1rem; margin-left: 1rem" v-html="dataSend.text.replace(/([.\n\r]+)/g, '<br/>')"></div>
使用css样式white-space: pre-line替代v-html
<div style="margin-top: 1rem; margin-left: 1rem; white-space: pre-line">{{ dataSend.text }}</div>
或者直接使用<pre></pre>标签