【无标题】

文章目录

需求

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

分析

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

  • 上代码
  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;
}
相关推荐
止观止5 小时前
告别 require!TypeScript 5.9 与 Node.js 20+ 的 ESM 互操作指南
javascript·typescript·node.js
zhougl9965 小时前
Vue 中使用 WebSocket
前端·vue.js·websocket
无名的小白5 小时前
openclaw使用nginx反代部署过程 与disconnected (1008): pairing required解决
java·前端·nginx
xyq20245 小时前
jEasyUI 自定义分页
开发语言
2601_949857435 小时前
Flutter for OpenHarmony Web开发助手App实战:文本统计
前端·flutter
.ZGR.5 小时前
认识数据结构:图——无人机防空平台的“衍生品”
java·开发语言·数据结构
光影少年5 小时前
智能体UI ux pro max
前端·ui·ux
酒鼎5 小时前
学习笔记(7-01)函数闭包
javascript
半梅芒果干5 小时前
vue3 实现无缝循环滚动
前端·javascript·vue.js
波波0075 小时前
Native AOT 能改变什么?.NET 预编译技术深度剖析
开发语言·.net