【无标题】

文章目录

需求

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

分析

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

  • 上代码
  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;
}
相关推荐
NiceCloud喜云14 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
wordbaby15 小时前
React Native + RNOH:跨页面数据回传的最佳实践与避坑指南
前端·react native
GISer_Jing15 小时前
Three.js着色器编译机制深度解析
javascript·webgl·着色器
丷丩15 小时前
MapLibre GL JS第22课:查看本地GeoJSON
前端·javascript·map·mapbox·maplibre gl js
AI玫瑰助手15 小时前
Python函数:默认参数的定义与注意事项
开发语言·python·信息可视化
油炸自行车15 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
肩上风骋15 小时前
C++14特性
开发语言·c++·c++14特性
Front思16 小时前
AI前端工程师需要具备能力+
前端·人工智能·ai
JAVA社区17 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展
弥树子17 小时前
踩坑记录:服务器内网调用接口,真实请求URL与官方公开URL不一致问题排查
开发语言·php