微信小程序,[渲染层错误] RangeError: Maximum call stack size exceeded

问题记录:

制作微信小程序有关html文本内容时使用了rich-text组件,渲染html时有报错: RangeError: Maximum call stack size exceeded

原因:可能html包含不识别的代码

一、 代码记录(名称乱写的)

// xxx.wxml
	<view class="www" wx:if="{{qqqq}}" >
		<rich-text nodes="{{qqqq}}"></rich-text>
	</view>
//xxx.js
onLoad: function (options) {
    this.setData({
      zzzzzzz:ooo.ppp
    }),
    getBBB(111).then(res=>{
      if (res.code == 200) {
        const ttStr = res.data.iii
        this.setData({
          ttContents: ttStr
        })
      }
      console.log()
    })
  },
// api.js
	export function getBBB(id) {
  		return request.get('xxx/xxx/xxx', { id: id })
}

二、解决方法

在js文件内加替换

.replace(/style="[^"]+"/gi, “”)
.replace(/style=’[^’]+’/gi, “”) //小程序展示要自己统一的样式,替换了行内样式
.replace(/( )/gi, “”) //替换了注释的内容这能替掉大部分
.replace(/<xml[^>]>(.|\n)</xml>/gi, “”) //替换了xml标签word粘贴带出一堆标签包含在xml里干掉它
.replace(/undefined/gi, “”) //里面莫名有个undefined 干掉

变成这样就解决了,(其他搜的出来的问题以及解决方法暂时在我这个错误里没用到)

//xxx.js
onLoad: function (options) {
    this.setData({
      zzzzzzz:ooo.ppp
    }),
    getBBB(111).then(res=>{
      if (res.code == 200) {
        const ttStr = res.data.iii.replace(/style="[^"]+"/gi, "")
		.replace(/style='[^']+'/gi, "")   //小程序展示要自己统一的样式,替换了行内样式
		.replace(/(<!--(.|[\r\n])*?-->)/gi, "") //替换了注释的内容这能替掉大部分
		.replace(/<xml[^>]*>(.|\n)*<\/xml>/gi, "") //替换了xml标签<xml></xml>word粘贴带出一堆标签包含在xml里干掉它
		.replace(/undefined/gi, "") //里面莫名有个undefined 干掉
      this.setData({
         ttContents: ttStr
        })
      }
      console.log()
    })
  },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Agatha方艺璇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值