export const FetchHandler = function (url,opt) {
let paramStr = '';
let token = '';
for(key in opt){
if (opt[key] !== ''){
if (typeof opt[key] === 'object') {
paramStr += key + '=' + JSON.stringify(opt[key]) + '&'
} else {
paramStr += key + '=' + opt[key] + '&'
}
}
}
paramStr = paramStr.substring(0,paramStr.length - 1)
return new Promise((resolve,reject) => {
AsyncStorage.getItem('token',(error,result)=>{
token = result;
}).then(result=>{
fetch(url, {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'token': token
},
body: paramStr
})
.then((response) => response.json())
.then(function (response) {
resolve(response)
})
.catch((reject)=>{
reject('request error');
})
});
})
};
vue--http请求的封装--token
你的关注,就是我的坚持!
推荐阅读
- Windows10安装mysql的方法
- 小说PC端和APP端的体验
- 账号登录测试,多表查询
- 协同过滤笔记
- The remote SSH server rejected X11 forwarding request.
- Liunx面试题
- ORA-28040: No matching authentication protocol
- 解析Tomcat内部结构和请求过程
- 博文阅读密码验证 - 博客园
- weblogic 的应用链接不上数据库报异常 Caused By: weblogic.common.ResourceException: Io exception: Connection reset 错误信息表示访问数据库异常,创建链接池失败