A crude encapsulated request with a token is returned to the 401 login page

1. Api.js file

function http(url, data, ) { return new Promise((resolve, reject) => { const app = getApp(); let request_token = wx.getStorageSync('accountInfo').token url += '? access_token=' + wx.getStorageSync('accountInfo').token wx.request({ url: app.globalData.baseURL + url, data: data, method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, success(res) { if (res.statusCode === 401) { wx.removeStorage({ key: 'accountInfo', }) return wx.redirectTo({ url: '.. /login/login', }) } res.statusCode === 200 ? resolve(res.data) : reject(res.data); }, fail(res) {reject(res)}})})} module.exports.http = HTTP // Expose HTTPCopy the code

2, app.js file import

const api = require('utils/api.js')
App({
  onLaunch: function () {},
  api:api,
  globalData: {}
})
Copy the code

3, inside the page to use

const app = getApp()
reqStats: function(data) {
    let url = 'a/b/c''
    app.api.http(url, data)
      .then(res => { })
      .catch((err) => {
        console.log(err)
      });
  }, 
Copy the code

Ok, can use

Part of the apple mobile phone can’t call wx. SaveImageToPhotosAlbum save photo albums to the problem

Problem: Don’t know the solution: Add authorization instructions to your app.json, i.e. insert the following code:

"Permission ":{"scope.userLocation": {"desc":" Your location information will be used for the effect display of the applet location interface "}, "scope.writePhotosAlbum":{"desc": "Only after you authorize the album permission can you save the picture normally"}},Copy the code

Page up and down drag blank problem, how to prohibit the page drag

Wechat mini program version update

To check whether the wechat applet is the latest version, insert the following code into app.js. Call it from onLaunch

checkForUpdate: function () { try { const updateManager = wx.getUpdateManager() updateManager.onUpdateReady(function () { wx.showModal({ Title: 'Update prompt ', Content:' The new version is ready. Do you want to restart the application? ', success: function (res) { if (res.confirm) { updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { }) } Catch (err) {console.log(' base library version is later than 1.9.90')}},Copy the code

Error or unavailable to obtain common TWO-DIMENSIONAL code parameters

Cause: In the development tool and debugging state can be used, the real machine does not work, because the real machine two-dimensional code parameters are not in options, but in options.q.

If (options.code) {// Scan into this.setData({code: options.code, })} if (options.q) {let link = decodeURIComponent(options.q) let code = link.split('=')[1] that.setData({ code:code, }) } }Copy the code

How to remove the border of the button

Solutions:

button::after{
    border: none;
}
Copy the code

Canvas Drawing Network pictures are not displayed

Problem cause: Don’t know, don’t want to check

Solution: 1. Configure the legal domain name downLoadFile for public platforms. 2

wx.downloadFile({
  url: that.data.mysrc,
  success: res=> {
    that.data.img = res.tempFilePath
  },fail:err=>{
    console.log(err)
  }
  })
Copy the code

Ok, solved!