axios的封装post和get

1、安装

npm install axios --save

2、main.js引用

import axios from 'axios';

axios的request方法
import axios from 'axios';
axios
  .request({
    method: "GET",
    url: "http://localhost:3000/comments",
  })
  .then((response) => {
    console.log(response);
  });


axios的post方法
axios
  .post("http://localhost:8000/demo", {
    name: "name1",
    age: "age1",
  })
  .then((response) => {
    console.log(response);
  });

猜你喜欢

转载自blog.csdn.net/jieweiwujie/article/details/124966873