【无标题】

文章目录

需求

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

分析

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

  • 上代码
  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;
}
相关推荐
钛态8 小时前
Vite 中的 CSS 工程化:从 CSS Modules 到 UnoCSS 的渐进式迁移
前端·vue·react·web
「QT(C++)开发工程师」8 小时前
C++ 11 常用for循环
开发语言·c++
我还记得那天8 小时前
0 初识C++
开发语言·c++
FfHUCisI9 小时前
Go 编译过程全景
开发语言·后端·golang
FfHUCisI9 小时前
Golang 语法分析与 AST:Parser 与 go/ast
开发语言·后端·golang
Csvn9 小时前
原型链、this 与闭包内存:三座深水区一次打通(含内存泄漏排查实战)
前端·javascript
lemon_sjdk10 小时前
ObjectProperty
java·开发语言·算法
葡萄城技术团队10 小时前
如何通过 JSON 数据源 / Web API 快速构建轻量级报表(Report)?
前端·json·原型模式