【无标题】

文章目录

需求

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

分析

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

  • 上代码
  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;
}
相关推荐
devilnumber24 分钟前
Java 递归算法 详解 + 核心要点 + 实战运用 + 避坑指南
java·开发语言·算法
asdfg12589632 小时前
JavaBean是什么?怎么理解?有什么用途?
java·开发语言
Cutecat_2 小时前
视频字幕处理工具横向:提取模式 vs 编辑模式,该如何选择
android·前端·ios·语音识别
dsyyyyy11012 小时前
JavaScript变量
开发语言·javascript·ecmascript
qq_422152573 小时前
PDF 加水印工具怎么选?2026 年文档版权保护方案对比
前端·pdf·github
kyriewen3 小时前
手写 Promise.all、race、any:不到 30 行代码,解决并发异步的所有姿势
前端·javascript·面试
z落落3 小时前
C#WinForm 窗体切换与窗体传值(登录跳转案例)+WinForm 窗体传值(从上往下传、从下往上传)
开发语言·windows·c#
allway23 小时前
How to Echo Multiline to a File in Bash [3 Methods]
开发语言·chrome·bash
weixin_462446233 小时前
手把手教你用 Bash 脚本自动更新 /etc/hosts —— 自动绑定网卡 IP 与节点名
开发语言·tcp/ip·bash
一个梦醒了3 小时前
安装git bash选项推荐
开发语言·git·bash