export const request = (url, method = "GET", data) => {
let _url = `${baseUrlPrefix}${url}`;
return new Promise((resolve, reject) => {
Taro.showLoading({
title: "正在加載"
});
Taro.request({
url: _url,
data: data,
method: method,
header: {
"content-type": "application/json"
},
success: res => {
console.log("從接口獲取到的數據", res);
let { code } = res.data;
Taro.hideLoading();
if (code === 200) {
resolve(res.data.data);
wx.hideLoading();
} else {
wx.showToast({
title: "數據請求錯誤"
});
}
},
fail() {
reject("接口有誤,請檢查");
}
});
});
};
taro封裝request請求
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.