//封装
http:(url,param={},method='post')=>{
return new Promise((resolve,reject) =>{
let loading = $zbb.loading();
param._t = store.state.radishH5Catch._t || '';
axios({
method,
url,
[method === 'post'? 'data':'params']:param
}).then(res=>{
if (res.data.flag === 0) {
loading.clear();
resolve(res.data.data);
console.log(url,res.data.data);
} else {
$zbb.msg(res.data.msg);
reject(res.data.msg);
if(res.data.msg === '请登录'){
router.push('/login');
}
}
}).catch((err)=>{
$zbb.msg('请求数据失败');
reject(err);
// loading.clear();
})
}).catch((reason) =>{
console.error('err:' + reason);
});
}
// 定义api
export const releaseDelApi = id =>http('/info',{id});
使用
async function(){
let res =await releaseDelApi (id);
console.log(res)
}
网友评论