GithubHelp home page GithubHelp logo

simple-wx-request's Introduction

简介

微信小程序request全局的简单封装

具体作用

  1. 封装了GET, POST方法的基本调用
  2. 对请求做了统一的拦截处理,可在每个请求前,做处理,例如添加统一token
  3. 对请求返回的数据进行了统一的处理,可在这里进行全局接口错误处理

使用方法

// wxRequest.js文件
import wxRequest from './index.js';

// 设置api域名
wxRequest.setConfig({ baseUrl: 'htttps://www.xx.com' })

// 请求拦截处理
wxRequest.interceptor.request((reqOpt) => {
  // your code here
  return reqOpt
})

// 对请求回来的数据进行统一处理
wxRequest.interceptor.response((response, reqOpts) => {
  const { code, message, success } = response.data
  // your code here example
  if (message) {
    uni.showToast({
      title: message,
      icon: 'none',
    })
    throw new Error(errorMsg)
  }
  return response
})

export default wxRequest

// get post的调用示例
wxRequest.post('/api/how/are/you', data, options)
wxRequest.post('/api/i/am/fine', data, options)

simple-wx-request's People

Contributors

cy0707 avatar

Stargazers

Mallee avatar back avatar 7Min avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.