JS设计模式总结笔记
# 原理
web页面修改富文本中上传的图片的大小
# 代码实现
<template>
</template>
<script setup>
// 通过正则表达式匹配富文本中原本的style风格
const rel = /style\s*?=\s*?([‘"])[\s\S]*?\1/
// description-富文本的内容 通过正则表达式将匹配的style样式替换成空字符串
const newHtml = description.value?.replace(rel, '')
// 给富文本中的img添加max-width 最大宽度为100% 高度auto 的style样式
description.value=newHtml?.replace(/\<img/gi,'<img style="max-width:100%;height:auto;display:block;"') // eslint-disable-line
</script>
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
上次更新: 2024/08/07, 18:05:11