武装少女在线观看高清完整版免费,丝袜+亚洲区,少妇被cao高潮呻吟声,午夜伦情电午夜伦情电影,日日躁夜夜躁狠狠躁

小程序模板網(wǎng)

小程序版結(jié)合promise的axios風(fēng)格ajax請(qǐng)求函數(shù)

發(fā)布時(shí)間:2018-10-19 10:46 所屬欄目:小程序開(kāi)發(fā)教程

建議的小程序版本的axios函數(shù),之所以說(shuō)簡(jiǎn)易,因?yàn)橹皇怯昧顺S玫恼?qǐng)求方法外,然后添加了攔截器而已。
具體如下:

wxhttp


命名為wxhttp

具體的請(qǐng)求用法如axios

wxhttp#request(config)

wxhttp#get(url[,config])

wxhttp#delete(url[,config])

wxhttp#head(url[,config])

wxhttp#options(url[,config])

wxhttp#post(url[,data[,config]])

wxhttp#put(url[,data[,config]])

wxhttp#patch(url[,data[,config]])

攔截方法:

  1. 請(qǐng)求攔截

wxhttp.interceptors.request.use(handleRequest(config),handleError(err))

注意:handleRequest需要返回處理后的config

  1. 返回?cái)r截

wxhttp.interceptors.response.use(handresponse(res))

注意:handleResponse需要返回處理后的res

例子:

import $http from "../../utils/http"
export default {
  name: 'seckillHome',
  data() {
    return {

    }
  },
  onShow() {
    // 請(qǐng)求攔截
    $http.interceptors.request.use(function (config) {
      console.log(`請(qǐng)求攔截`, config)
      // 此處設(shè)置的數(shù)據(jù)將與請(qǐng)求的數(shù)據(jù)進(jìn)行合并,如果自動(dòng)同名則以攔截的為準(zhǔn)。
      config.data = {
        address: "北京市東城區(qū)"
      }
      return config
    })

    $http.post('https://www.baidu.com', {
      name: 'cdd',
      age: 23
    }).then(res => {
      console.log(`結(jié)果是`, res)
    })
  }
}

因?yàn)槭褂昧藀romise風(fēng)格,所以可以使用Promise.all方法來(lái)進(jìn)行并發(fā)請(qǐng)求。



易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://www.kknew.com.cn/wxmini/doc/course/24898.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢(xún): 點(diǎn)擊咨詢(xún)
在線(xiàn)客服
易小優(yōu)
轉(zhuǎn)人工 ×