Giter VIP home page Giter VIP logo

frontend's Introduction

Frontend

P1: 关于axios的练习

统一设置

baseUrl=http://1.1.1.1
  1. 发起 Get请求,并通过queryparams方式传参 a=1,b=2
  2. 发起 POST请求,并通过application/x-www-form-urlencoded 方式传参 a=1,b=2
  3. 发起 PUT 请求,并通过queryparams传参a=1,同时通过application/json方式传参b=2
  4. 发起 POST请求,并通过 multipart/form-data 传文件
  5. 发起 DELETE请求,通过 text/plain 方式传参
  6. 发起POST请求,并指定proxy,其中host=1.1.1.1, port=999
  7. 发起POST请求,并实现基本认证功能(先了解什么是HTTP basic Auth),username=wlike password=19991231
  8. 最后,请封装一个request函数,内含一个axios实例,并添加以下逻辑:
    • 使用axios的validateStatus属性,让http状态码200~400范围都走axios的then函数(then函数内判断200状态码时打印Response数据),其他走catch函数(打印具体err)
    • 对于传入的data,若是get请求就填入axios的params,否则填入data

第八题要求实现如下效果

function request(url, type = 'GET', data = {}) {
   // TODO 实现此函数
}

// 下面是request的使用示例
export default {
    login(username, password) {
        return request('/auth/login', 'POST', {username, password})
    },
    get_user_info() {
        return request('/auth/get_user_info')
    }
}

练习备注

  • index.js中编写代码

启动项目

cd about_axios/
npm i
npm start   // 打开网页  F12观察控制台是否有错误

frontend's People

Contributors

chasespace 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.