【无标题】

文章目录

需求

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

分析

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

  • 上代码
  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;
}
相关推荐
harrain16 分钟前
什么!vue3.4开始,v-model不能用在prop上
前端·javascript·vue.js
阿蒙Amon5 小时前
TypeScript学习-第7章:泛型(Generic)
javascript·学习·typescript
睡美人的小仙女1275 小时前
Threejs加载环境贴图报错Bad File Format: bad initial token
开发语言·javascript·redis
fanruitian6 小时前
uniapp android开发 测试板本与发行版本
前端·javascript·uni-app
rayufo6 小时前
【工具】列出指定文件夹下所有的目录和文件
开发语言·前端·python
RANCE_atttackkk6 小时前
[Java]实现使用邮箱找回密码的功能
java·开发语言·前端·spring boot·intellij-idea·idea
摘星编程6 小时前
React Native + OpenHarmony:Timeline垂直时间轴
javascript·react native·react.js
缺点内向6 小时前
C#编程实战:如何为Word文档添加背景色或背景图片
开发语言·c#·自动化·word·.net
一起养小猫7 小时前
Flutter for OpenHarmony 实战:记账应用数据统计与可视化
开发语言·jvm·数据库·flutter·信息可视化·harmonyos
zhougl9967 小时前
Java 所有关键字及规范分类
java·开发语言