钉钉小程序如何使用 application/json;charset=utf-8

在外部app.js中

App({
  globaldata: {
    serverurl:'实际地址',
   authToken:'token'
    // serverurl: 'http://172.16.1.47:7001',
    authCode: '',
  },
  // 封装网络请求
  https(httpstype, url, data) {
    dd.showLoading();
    let endurl = encodeURI(getApp().globaldata.serverurl + url);  //全局里边不能用this getApp()代表this
    return new Promise((resolve, reject) => {
      dd.httpRequest({
        headers: {
          "Content-Type": 'application/json;charset=utf-8',
          "token": getApp().globalData.authToken
        },
        url: endurl,
        method: httpstype,
        data: data,
        dataType: 'json',
        success: (res) => {
          resolve(res)
        },
        fail: (res) => {
          reject(res)
 
        },
        complete: (res) => {
          dd.hideLoading()
        }
      })
    })
  },
})

在index.js中引入

Page({
  data: {},
  onLoad() {
    let app=getApp()
    let dada= {pageNum: '1',pageSize:'99999',firstDept:app.globalData.firstDept}
    dada=JSON.stringify(dada)
    app.https('post','dingapi/pri/xttCRM/babyInfo/getfirstDept',dada)
    .then((res)=>{console.log('对了',res)}
    )
  },
});

原文:https://blog.csdn.net/weixin_30536513/article/details/102122187?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.control

你可能感兴趣的:(钉钉小程序如何使用 application/json;charset=utf-8)