VUE + IVIEW related problems (2): The various parameters of the request transmission process

Request Category:

  • POST
  • GET
  • PUT
  • DELETE
  • OPTIONS

First of all I, as a developer background I'm used to access coherent processing at me, at first said junction reference mode

  1. @RequestBody body of data read json
  2. Parameters in the URL of the read request @RequestParam
  3. @PathVisiable routing parameters, in order to meet RestFul style
  4. ... nothing, is generally carried out at the request of distinction: POST Request Form is form, get or RequestParam way, of course, this is not absolute, you have to receive parameters in the URL with POST is also possible

Now it is under the front right way parameter passing:

POST request

Note that I said that the convention is not mandatory rules.

export const saveUser = (data) => {
  return axios.request({
    url: 'user/user/save',
    data,
    method: 'post'
  })
}

@RequestBody

The following is the time routing process

// 请求拦截
instance.interceptors.request.use(config => {
  config.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; 
  config.data = JSON.stringify(config.data);
  return config
}, error => {
  return Promise.reject(error)
})

FORM Form form

import qs from 'qs';
// 请求拦截
instance.interceptors.request.use(config => {
  config.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
  config.data = qs.stringify(config.data);
  return config
}, error => {
  return Promise.reject(error)
})

File Upload

// 请求拦截
instance.interceptors.request.use(config => {
  config.headers.post['Content-Type'] = 'multipart/form-data';
  return config
}, error => {
  return Promise.reject(error)
})

These are the treatment for POST requests

GET request

get requests are generally stitching request

export const userList = (params) =>{
  return axios.request({
    url: 'user/user/list',
    params,
    method: 'get'
  })
}

It does not require any special treatment to

PUT and DELETE requests Request

Basically use @PathVisiable

He published 183 original articles · won praise 37 · views 160 000 +

Guess you like

Origin blog.csdn.net/zhuwei_clark/article/details/104791083