当项目中遇到后端返回的数据带格式的字符串时,前端该怎么处理保留其空格和换行符的问题:
方法一:css方法
white-space: pre-wrap; // css保留空格和换行符
white-space: pre-line; // css保留换行符
方法二: pre标签法(推荐)
使用<pre>{{content}}</pre>
标签,同时需要注意,content与pre标签要在同一行,否则会出现首行缩进现象。
当项目中遇到后端返回的数据带格式的字符串时,前端该怎么处理保留其空格和换行符的问题:
方法一:css方法
white-space: pre-wrap; // css保留空格和换行符
white-space: pre-line; // css保留换行符
方法二: pre标签法(推荐)
使用<pre>{{content}}</pre>
标签,同时需要注意,content与pre标签要在同一行,否则会出现首行缩进现象。