yuesha
yuesha
发布于 2025-01-17 / 803 阅读 / 0 评论 / 0 点赞

uniapp运行的微信小程序发起请求uni.request时报错memory-leak

写在前面

今天在做uniapp开发的过程中,遇到了这个问题,,

发起请求时出现warning

出现报错信息为:

[memory-leak] triggerOnEvent called on a deprecated instance

一头懵逼

解决方案

uni.request({
    url: "目标地址",
    dataType: "json",
    responseType: "json",
    method: "POST",
    data: 数据对象,
    header: {
        "Content-Type": "application/json",
    },
    success(resp) {
        // 响应处理回调函数
    },
    fail(e) {
        console.log(e);
    }
})

主要原因就是其中有这个

responseType: "json"

去掉就可以正常返回了。

就是这个样子

请求代码的问题

uni.request({
    url: "目标地址",
    dataType: "json",
    method: "POST",
    data: 数据对象,
    header: {
        "Content-Type": "application/json",
    },
    success(resp) {
        // 响应处理回调函数
    },
    fail(e) {
        console.log(e);
    }
})

借鉴帖子:

https://developers.weixin.qq.com/community/develop/doc/0006a8fb100f40290c910a8086b800

注意:

这里的dataType代表着请求参数是json格式,文档中写的意思是:

如果设为 json,会对返回的数据进行一次 JSON.parse,非 json 不会进行 JSON.parse


评论