【无标题】

文章目录

需求

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

分析

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

  • 上代码
  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;
}
相关推荐
mCell6 小时前
GSAP ScrollTrigger 详解
前端·javascript·动效
gnip6 小时前
Node.js 子进程:child_process
前端·javascript
excel9 小时前
为什么在 Three.js 中平面能产生“起伏效果”?
前端
excel10 小时前
Node.js 断言与测试框架示例对比
前端
天蓝色的鱼鱼12 小时前
前端开发者的组件设计之痛:为什么我的组件总是难以维护?
前端·react.js
codingandsleeping12 小时前
使用orval自动拉取swagger文档并生成ts接口
前端·javascript
石金龙13 小时前
[译] Composition in CSS
前端·css
白水清风13 小时前
微前端学习记录(qiankun、wujie、micro-app)
前端·javascript·前端工程化
Ticnix13 小时前
函数封装实现Echarts多表渲染/叠加渲染
前端·echarts
用户221520442780013 小时前
new、原型和原型链浅析
前端·javascript