Applet setting request header

How to set the request header in the applet, no more nonsense

    wx.request({
            url: BaseUrl + url, //将传入的网址与baseurl拼接
            data:data || {}, //有data就传入data,没有设置为空
            method:"POST", //请求的类型
            header: {//设置请求头
              'content-Type': 'application/json',
              'Cookie':wx.getStorageSync("key"),//读取本地存储的token//将token去读,请求时会将请求头带过去
              },
            success (res) {//成功时的回调
              if(res.data == "{code:9006}"){
                wx.showModal({
                  title: '提示',
                  showCancel: false,
                  content: '登入失效,请重新登入',
                  success(res) {
                    if (res.confirm) {//confirm为true时代表用户点击了按钮
                      wx.reLaunch({
                        url: '/pages/log/log'
                      });
                    }
                  }
                })
              }else if(res.data == "{code:1903}"){
                wx.showToast({
                  title: '请求超时,请重新尝试',
                  icon:"none",
                  mask:true,
                })
              }
              resolve(res)
            },

Guess you like

Origin blog.csdn.net/xiaokangna/article/details/122232719