【无标题】

文章目录

需求

将后端返回的字符串内容按照换行进行展示,且要求首行缩进

分析

控制台打印后端返回的数据是有换行操作的,如果我们直接把接到的数据放到页面上,就会冲毁原有样式,因此在接到数据后需要进一步处理

  • 上代码
  1. 获取数据进行处理成数组
c 复制代码
getMessage(tempData).then(res => {
        if (res && res.code == 200) {
            let msg = res.rows[0].remarks
            console.log(msg);
            JSON.parse(JSON.stringify(msg).replace(/\\n/g, '<br/>'))
            const message = JSON.stringify(msg)
            const str = message.split(/\\n/g)
            str.forEach(text => {
                Info.value.push(text.replace(/"/g, ''))
            })
        }
    })
  1. 将数组循环遍历到页面上做展示,并添加首行缩进的样式
c 复制代码
<div class="content">
     <div v-for="(item, index) in Info" :key="index">
         <p v-html="item"></p>
     </div>
 </div>
c 复制代码
.content {
    text-indent: 2em;
    line-height: 2.5;
}
相关推荐
崇山峻岭之间10 分钟前
Matlab学习记录05
开发语言·学习·matlab
用户479492835691510 分钟前
你每天都在用的 JSON.stringify ,V8 给它开了“加速通道”
前端·chrome·后端
狗狗摇屁屁13 分钟前
JS手写防抖
开发语言·javascript·ecmascript
派大鑫wink15 分钟前
【Day7】构造方法与 this 关键字:初始化对象的正确姿势
java·开发语言
智算菩萨16 分钟前
实战:用 Python + 传统NLP 自动总结长文章
开发语言·人工智能·python
沐知全栈开发16 分钟前
WebForms HashTable 深入解析
开发语言
子夜江寒16 分钟前
基于 Python 库使用贝叶斯算法与逻辑森林
开发语言·python·算法
JIngJaneIL16 分钟前
基于java+ vue办公管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
清风细雨_林木木22 分钟前
Chart.js和 Echart的区别
开发语言·javascript·ecmascript
wjs202424 分钟前
JSP 指令
开发语言