小程序的请求都被封装在api.js 里面,类似与vue那样的
const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
const FORM = 'FORM';
const DELETE = 'DELETE';
const baseUrl = 'http://xxxjt/xcx/';
var HEADER = {
token: '',
'content-type': 'application/json',
}
function request(method, url, data) {
return new Promise(function(resolve, reject) {
wx.request({
url: baseUrl + url,
method: method,
data: method === POST ? JSON.stringify(data) : data,
header: HEADER,
success(res) {
//请求成功
//判断状态码---errCode状态根据后端定义来判断
if (res.data.code == '000000') {
resolve(res);
} else {
//其他异常
wx.showToast({
title: res.data.desc,
icon: 'none',
duration: 1500
})
reject('运行时错误,请稍后再试');
}
},
fail(err) {
//请求失败
reject(err)
}
})
})
}
const API = {
loginAPI: (data) => request(POST, 'user-info/login', data),
getListRwo: (data) => request(POST, 'rwo/getList-rwo', data),
getEnumsValueByCode: (data) => request(GET, 'dic-enums/getList-ev', data),
addRwo: (data) => request(POST, 'rwo/add-rwo', data),
getDetail: (data) => request(GET, 'rwo/getDetail-rwo', data),
getRepairPeople: (data) => request(GET, 'user-info/getUI', data),
assign: (data) => request(POST, 'rwo/assign-rwo', data),
repair: (data) => request(POST,'rwo/finish-rwo',data),
check: (data) => request(POST,'rwo/check-rwo',data)
}
module.exports = {
API: API,
HEADER: HEADER
}
我想请求这个getListRwo接口的时候,怎么把参数动态绑定到url上呢?
url都已经写死了,没办法绑定了 你可以把这个当做一个参数从外面的页面传进来,像data一样