钉钉小程序封装请求地址
生活随笔
收集整理的這篇文章主要介紹了
钉钉小程序封装请求地址
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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)})},}, })
?
轉載于:https://www.cnblogs.com/wgl0126/p/11419085.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的钉钉小程序封装请求地址的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [小程序]微信小程序登陆并获取用户信息
- 下一篇: 钉钉小程序数据传递——子传父,父传子