作者:山人 | 来源:互联网 | 2023-05-19 16:02
networkrequest.js封装ajax要求consthttp(url,type,parameter){returnnewPromise((resolve,reject)
network/request.js
//封装ajax要求
const http = (url,type,parameter) => {
return new Promise((resolve,reject) => {
wx.request({
url:url,
method:type,
success:function (res) {
resolve(res.data);
},
fail:function (err) {
reject(err)
}
})
})
}
export {http}
在index.wpy中运用
import { http } from '../network/request';
http("https://easy-mock.com/mock/5cc66aee7a9a541c744c9c07/example/restful/:id/list","GET").then(function (res) {
console.log(res)
}).catch(function (err) { });
我的微信民众号:天字一等