promise封装wx请求

api.js
function http( url, data = {}, method= 'get') {

return new Promise( function ( resolve, reject) {
wx. request({
url: url,
data: data,
method: method? method: 'get',
success : ( res) => {
resolve( res)
},
fail :( res) =>{
reject( res)
}
})
})
}

export { http }

index.js
adver(){
console. log( '页面已创建')
http( 'https://unify.playonweixin.com/site/get-advertisements',{
sign: 'xxx'
}, 'post'). then( res =>{
console. log( '页面创建参数', res)
})
},

你可能感兴趣的:(ajax,js)