釘釘小程序封裝請求地址


1.在最外層的app.js中

App({
  globaldata: {
    serverurl:'實際地址',
    // 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?id=' + this.data.curTbmId + '&time=' + startdate).then(res => {
        console.log(res)
      })
    },
  },
})

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM