You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
880 B

const BASE_URL = 'http://www.pgyer.com/apiv2'
export const request = (options) => {
return new Promise((resolve, reject) => {
// 获取用户令牌
let token = ''
// 设置请求头
const header = {
'Content-Type': 'application/x-www-form-urlencoded',
// Authorization: `Bearer ${token}`,
...options.header // 可以传入额外的请求头参数
}
// ⭐在发送请求之前执行拦截操作
options.data._api_key = '0b9b69b071c1baa43015b841534e9001'
uni.request({
url: BASE_URL + options.url, //接收请求的API
method: options.method || 'GET', //接收请求的方式,如果不传默认为GET
data: options.data || {}, //接收请求的data,不传默认为空
header: header, //接收请求的header
success(res) {
resolve(res.data) // 使用resolve将数据传递出去
},
fail: (err) => {
reject(err)
}
})
})
}