fjc0k / taro-axios

在 Taro 中使用 axios。
https://www.npmjs.com/package/taro-axios
MIT License
139 stars 8 forks source link

真机预览报错: Unhandled promise rejection Error: Network Error #29

Closed Ark-Chen closed 3 years ago

Ark-Chen commented 3 years ago
import axios from 'taro-axios';

return new Promise((resolve, reject) => {
            const instance = axios.create();
            addAxiosInterceptor(instance);
            instance({
                method: 'post',
                headers: {
                    'Content-Type': 'application/json;charset=utf-8'
                },
                url: config.url + api,
                data: params
            }).then((response) => {
                resolve(response);
            }).catch((err) => {
                console.log(err)
                reject(err);
            });
        });

总是在catch中报错:

VM13:2 Unhandled promise rejection Error: Network Error
    at createError ([__wxPluginCode__]:13521)
    at eval ([__wxPluginCode__]:14543)
    at eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:66297)
    at eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:66406)
    at A (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:68857)
    at A.exports (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:27577)
    at E.<computed> (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:32976)
    at Number.n (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:32679)
    at Function.eval (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:3541)
    at C (eval at n.call.document (runtime.js?devtools_ignore=true:1), <anonymous>:2:121922)

taro v2.2.16 taro-axios 0.7.0

微信开发者工具内调接口是好的,真机预览就报这个错,调试看到控制台network请求并没有发出去,有什么办法解决吗,比较急,大神们帮帮忙

Ark-Chen commented 3 years ago

@fjc0k 帮帮忙

fjc0k commented 3 years ago

看看域名是否加入微信的request合法域名,或者手机预览打开调试模式

Ark-Chen commented 3 years ago

看看域名是否加入微信的request合法域名,或者手机预览打开调试模式

微信开发者工具我把检测合法域名给关掉了,刚才在小程序掉了个接口是ok的,插件内还是会报错

Ark-Chen commented 3 years ago

image 真机调试的报错信息

Ark-Chen commented 3 years ago

可以了,原来微信开发者工具对域名校验的关闭处理对插件不起作用,即使当前开发的就是插件,依然不起作用。配置了插件的域名之后问题解决了。之前开发者工具关闭了域名校验,模拟器一直没问题,就忽略了这个点。感谢提醒@fjc0k 问题已解决。