首页 > 教程
微信小程序原生wx.request简单封装
- 2025-04-07
- 1138 ℃
调用方法
import { get, post } from "../../request/request";
// GET请求
const _res = await get("https://api.vvhan.com/api/ian");
console.log(_res);
// POST请求
const _res = await post("https://api.vvhan.com/api/ian");
console.log(_res);request.js
const request = (url, options) => {
return new Promise((resolve) => {
options.isLoading &&
wx.showLoading({
title: "正在加载",
});
wx.request({
url,
method: options.method,
data: options.data,
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success(res) {
resolve(res.data);
options.isLoading && wx.hideLoading();
},
fail(error) {
options.isLoading && wx.hideLoading();
wx.showToast({
icon: "none",
title: "请求失败",
duration: 1400,
});
},
});
});
};
const get = (url, options = {}, isLoading = true) => {
return request(url, {
method: "GET",
data: options,
isLoading,
});
};
const post = (url, options = {}, isLoading = true) => {
return request(url, {
method: "POST",
data: options,
isLoading,
});
};
module.exports = {
get,
post,
};下一篇:微信小程序登陆封装
相关内容
fastadmin基于ZipArchive...
大学可以不用买学校订的教材
jQuery点击生成二维码QRC...
mysql数据库优化
能自动帮你过人机验证的工具
微信读书限制非会员,6招...
2025年8款免费且好用的图...
24年强开花呗教程
-
闲鱼数据的获取与下载
2025-04-08 1529
-
微信最快的搜索方法 - 输入#号加内容
2025-06-22 1384
-
如何搜索到自己想要的资源
2025-03-10 1410
-
php使用header()函数导出excel表格
2021-07-12 1472
-
微信商户号申请
2024-05-13 1582
-
什么是深网?有危险吗?如何从A-Z进入深网
2024-04-24 2685
-
易支付对接微信商户完整流程
2024-02-06 4383
-
关于浏览器的选择
2025-03-03 1295
-
免费下载PPT模板的网站来了
2025-03-10 1483
-
网页上的视频怎么下载
2021-11-22 686
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


进入有缘空间
点击分享文章