代码拉取完成,页面将自动刷新
微信集成化网络框架
软件架构说明
netTaskByConf({
host:"https://wenwen.sogou.com/z/q721011130.htm",
method:"GET"
}).then((res, fail) => {
console.log(res);
console.error(fail);
});
netTaskByConf({
host:"https://wenwen.sogou.com/z/q721011130.htm",
method:"GET",
success:(res) => {
console.log(res);
},
error:(fail)=>{
console.error(fail);
}});
注意 : 标 * 为必填参数
普通请求:
{
config:{
host: "* string (服务器地址)",
method: "* string (接口方式)",
headers: "object headers",
sync: "bool (同名请求,是否同步)",
path: "string (接口路径)",
port: "number (接口端口)"
},
data: "参数",
timeout: "number (超时时间,默认5000)",
resInterceptor: "function 响应拦截 ",
requestInterceptor: "function 请求拦截 "
}
文件上传:
{
config:{
host: "* string (服务器地址)",
headers: "headers",
sync: "bool (同名请求,是否同步)",
path: "string (接口路径)",
port: "number (接口端口)"
},
filePath: "* string 需要上传的文件路径",
name: "* string 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容",
data: "object 额外的参数",
timeout: "number (超时时间,默认5000)",
resInterceptor: "function 响应拦截 ",
requestInterceptor: "function 请求拦截 "
}
eg:
// request.js
const {WXYHNetworking} = require("./submodule/index");
const requestInterceptor = function(options){
return options;
}
const resInterceptor = (res) => {
return res;
};
module.exports = new WXYHNetworking({ resInterceptor ,requestInterceptor});
const host = getApp().config.host;
const port = getApp().config.port;
const netWork = require("../utils/request");
module.exports.getPersonDetail = function (params) {
return netWork.netTaskByConf({
params,
config: {
host,
path: "personnel/person/(id)",
port,
method: "get",
},
timeout: 8000,
});
};
eg:
// request.js
const {env} = require("./envList");
const traceUser = true;
const {YHCNetWoking} = require("./submodule/index");
const mrequest = new YHCNetWoking({env,traceUser});
module.exports = mrequest;
// api.js
const net = require("../request");
module.exports.login = function (data) {
return net.request({
name: "user",
data: {
type: "login",
...data
}
})
}
进阶
配置拦截器
// request.js
const requestInterceptor = function(options){
wx.showLoading({
title: 'none'
})
return options;
}
const resInterceptor = function(res){
const {result} = res;
const {code,msg} = result;
if (code != 200) {
wx.showToast({
title: msg,
icon:"error"
})
}
wx.hideLoading()
return result;
}
const mrequest = new YHCNetWoking({env,traceUser,resInterceptor,requestInterceptor});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。