【无标题】

文章目录

需求

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

分析

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

  • 上代码
  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;
}
相关推荐
xieliyu.6 小时前
Java算法精讲:双指针(二)
java·开发语言·算法
云水一下7 小时前
TypeScript 从零基础到精通(五):高级类型与泛型
前端·javascript·typescript
何以解忧,唯有..7 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
counterxing7 小时前
vibe coding 之后,我更不想打字了
前端·agent·ai编程
雪的季节7 小时前
RabbitMQ详解
开发语言
云水一下7 小时前
TypeScript 从零基础到精通(六):类型声明与模块化
javascript·typescript
copyer_xyf7 小时前
Python 模块与包的导入导出
前端·后端·python
研☆香7 小时前
es6新特性功能介绍(四)
前端·ecmascript·es6
微扬嘴角7 小时前
React篇1--JSX语法规则、组件、组件实例的3大特性
前端·react.js·前端框架
ice8130331818 小时前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib