umi-request icon indicating copy to clipboard operation
umi-request copied to clipboard

用在小程序上可以吗

Open 1075488066 opened this issue 1 year ago • 5 comments

把原来中间件全去去掉。

1075488066 avatar Mar 31 '23 07:03 1075488066

我试的不行,报错: TypeError: Cannot read property 'fetch' of undefined

niujianqiang123 avatar Nov 08 '23 01:11 niujianqiang123

我试的不行,报错: TypeError: Cannot read property 'fetch' of undefined

得自己改部分源码了

1075488066 avatar Nov 08 '23 02:11 1075488066

对,小程序环境没有原生的fetch,umi-request里面使用了第三方的polyfill,但是挂载fetch挂错了对象,如果改源码,直接用wx.request替换比较合适,做一些字段兼容对接就可以了,如果作者能兼容下小程序就更好了,哈哈哈~

niujianqiang123 avatar Nov 08 '23 02:11 niujianqiang123

我尝试着改了 /node_modules/isomorphic-fetch/fetch-npm-browserify.js // module.exports = self.fetch.bind(self); module.exports = globalThis.fetch.bind(globalThis); 发现报错没了,不知道有没有其他问题

niujianqiang123 avatar Nov 08 '23 02:11 niujianqiang123

对,小程序环境没有原生的fetch,umi-request里面使用了第三方的polyfill,但是挂载fetch挂错了对象,如果改源码,直接用wx.request替换比较合适,做一些字段兼容对接就可以了,如果作者能兼容下小程序就更好了,哈哈哈~

改一点代码就行,我之前改了做成一个npm的包

1075488066 avatar Nov 08 '23 02:11 1075488066