调用 axios 异步请求,在请求的 then 回调函数中,使用了 MD5 加密,下方为类似代码
loginBefore(UserName, PassWord) {
return new Promise(function (resolve, reject) {
let loginObj = {
axios(login).then((res) => {
let Login = Base.encode(UserName) + AccessCode + md5(PassWord); //报错是此行代码导致
...
}).catch((err) => {
reject(err)
})
}
})
}
上面代码本身执行没什么问题,主要是两个形参,UserName, PassWord
let info = {
method: 'POST',
url: '...',
headers: {
'Content-Type': 'application/json'
}
};
axios(info).then((rep) => {
if(rep.data && rep.data.status === 200) {
username = rep.data.username;
password = rep.data.password;
}
}).catch((err) => {
console.log('err', err);
})
loginBefore(username, password).then((res) => { //该函数就是上面执行报错的函数
...
})
用户名和密码都是查询接口而来,由于接口查询的数据是通过回调函数拿到的,回调函数又是在任务队列中,等待主线任务执行完毕后,再执行任务队列,异步导致的数据还没查询出来,就使用,导致 MD5 中的参数是 undefined,所以报出 input is invalid type 输入类型错误的提示。
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- azee.cn 版权所有 赣ICP备2024042794号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务