码迷,mamicode.com
首页 > 微信 > 详细

钉钉小程序封装请求地址

时间:2019-08-27 17:06:14      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:div   地址   ati   asc   封装   type   encodeuri   ESS   rom   

1.在最外层的app.js中

App({
  globaldata: {
    serverurl:‘https://api.dadungou.site:9043‘,
    // serverurl: ‘http://172.16.1.47:7001‘,
    authCode: ‘‘,
  },
  // 封装网络请求
  https(httpstype, url, data) {
    dd.showLoading();
    let endurl = encodeURI(this.globaldata.serverurl + url);
    return new Promise((resolve, reject) => {
      dd.httpRequest({
        headers: {
          "Content-Type": ‘application/json;charset=utf-8‘,
          Authorization: ‘Bearer ‘ + ‘eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI1ZDVjOTkwODY1NmZmODAwYTE3ZTExNzUiLCJyYW5kb20iOiJjNjJhNWE2ZDk3OTliMTE1IiwidXNlcm5hbWUiOiLnlJjkuJzkuJwiLCJpYXQiOjE1NjY0NDE4OTR9.LZFdeYmNUCes-xF2HdFIGER4xVddDYn4RvtI3n1kLzs‘
        },
        url: endurl,
        method: httpstype,
        data: data,
        dataType: ‘json‘,
        success: (res) => {
          resolve(res)
        },
        fail: (res) => {
          reject(res)

        },
        complete: (res) => {
          dd.hideLoading()
        }
      })
    })
  },
})

2.使用请求,在组件中请求数据

let app = getApp()

Component({
  methods: {
    getData() {
      app.https(‘GET‘, ‘/api/v1/dailyTunneling?tbm_id=‘ + this.data.curTbmId + ‘&time=‘ + startdate).then(res => {
        console.log(res)
      })
    },
  },
})

  

 

钉钉小程序封装请求地址

标签:div   地址   ati   asc   封装   type   encodeuri   ESS   rom   

原文地址:https://www.cnblogs.com/wgl0126/p/11419085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!