vue的axios

305 阅读1分钟

在main.js里也得引入axios

   import axios from "axios";
   get() {
      axios({
        method: "post",
        url: "http://api****",
        timeout: 4000, // 请求4秒无响应则会超时
        data: {
          phone: "15500000000",
          fromType: "",
          name: "",
        },
        headers: {
          "Content-Type": "application/json"
        }
      })
        .then(res => {
          console.log(res);
        })
        .catch(error => console.error("请求超时"));
    }