小程序富文本图片宽度自适应

解决这个问题

创建一个util.js文件,图片的最大宽度设置为100%就行了

function formatRichText(html) {
	let newContent =  html.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"');

	return newContent;
}

module.exports = {
	formatRichText
}

使用方法

引入util.js

const util = require('util.js');

 转化富文本内容

hahahha() {
    this.post.content = img.formatRichText(this.post.content)
},

效果:

相关推荐

  1. 程序设置图片高度适应

    2024-03-27 06:28:06       35 阅读
  2. 微信程序图片适应

    2024-03-27 06:28:06       23 阅读
  3. el-dialog宽度适应

    2024-03-27 06:28:06       44 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 06:28:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 06:28:06       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 06:28:06       82 阅读
  4. Python语言-面向对象

    2024-03-27 06:28:06       91 阅读

热门阅读

  1. 模拟实现字符串函数1(详细版本)

    2024-03-27 06:28:06       31 阅读
  2. VUE3——reactive对比ref

    2024-03-27 06:28:06       41 阅读
  3. 通过 Docker 实现国产数据库 OpenGauss 开发环境搭建

    2024-03-27 06:28:06       39 阅读
  4. 最大子段和和最大子矩阵|动态规划

    2024-03-27 06:28:06       37 阅读
  5. 关于Redission读写锁

    2024-03-27 06:28:06       37 阅读
  6. 为什么不是Github Copilot,不是 Devin 而是 AutoCoder

    2024-03-27 06:28:06       40 阅读
  7. 文件读写篇

    2024-03-27 06:28:06       34 阅读