小程序
小游戏
企业微信
微信支付
扫描小程序码分享
目前想给所有接口的header添加一个key,不知小程序是否有提供全局处理的方法
5 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
开发者自己包装一个 request 即可
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
自己封装一层
const request = function (config = {}) {
request =
function
(config = {}) {
config.header={
'content-type':'application/x-www-form-urlencoded'
}
wx.requset(config);
在app.js的globalData中定义一个header,然后加一个处理所有请求的函数就可以了。例如:
fetch:
(options) {
let header =
this
.header
return
new
Promise((resolve, reject) => {
const requestTask = wx.request({
method: options.method,
header: header,
url: options.url,
data: options.data,
success: function (res) {
success:
(res) {
resolve(res)
},
fail:
(res) {},
complete:
() {}
})
like this
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
开发者自己包装一个 request 即可
自己封装一层
const
request =
function
(config = {}) {
'content-type':'application/x-www-form-urlencoded'
}
wx.requset(config);
}
在app.js的globalData中定义一个header,然后加一个处理所有请求的函数就可以了。例如:
fetch:
function
(options) {
let header =
this
.header
return
new
Promise((resolve, reject) => {
const requestTask = wx.request({
method: options.method,
header: header,
url: options.url,
data: options.data,
success:
function
(res) {
resolve(res)
},
fail:
function
(res) {},
complete:
function
() {}
})
})
}
like this