axios get 和 post 请求

get请求
axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });

post请求
axios.post('/user', {
 firstName: 'Fred',
 lastName: 'Flintstone'
})
.then(function (response) {
 console.log(response);
})
.catch(function (error) {
 console.log(error);
});

 

 

 

php 比较容易接受的方式

get

      axios.get('http://...?num=' + this.num).then(
        (res) => console.log(res.data)
      )

 

post

      axios.post('http://...', params, {
        transformRequest: [ // 转化要传入的为字符串
          function (data) {
            let str = ''
            for (const key in data) {
              str += key +
              '=' +
              JSON.stringify(data[key]) + '&'
            }
            return str
          }
        ],
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then()

 

 
posted @ 2021-08-02 10:47  qcjdp  阅读(106)  评论(0编辑  收藏  举报

Bill

Jerry

Evil