axios中get和post请求

post请求

https://www.cnblogs.com/zhouxiaohouer/p/7999479.html

由于post传参的特殊性,所以
import qs from 'qs';


Vue.prototype.$qs = qs;


this.$axios.post('http://localhost:8081/postinfo',this.$qs.stringify({
        firstName:'Fred',
        lastName:'Flintstone'
      }))
      .then(function(res){
        console.log(res.data);
      })
      .catch(function(err){
        console.log(err);
      });

get请求

axios.get('/user')
              .then(function (response) {
                  console.log(response)
                console.log(JSON.parse(response.data));
              })
              .catch(function (error) {
                console.log(error);
              });

猜你喜欢

转载自blog.csdn.net/Kalama/article/details/82215845