博主首页

vue发送ajax请求

使用的版本信息

 

 

 

npm install axios

 

 

 发送post请求

如果后端已经配置了跨域  还是报错

加上

 withCredentials: false,

 

      axios.post("http://127.0.0.1:9000/dev/app/auth/login-secret",{}).then(function (response){

        // eslint-disable-next-line no-unused-vars
      }).catch(function (error){

      })
    axios.post(that.$baseUrl+"/remote/getDayPlans",
         JSON.stringify(that),
        {
          withCredentials: false,
          headers:{
            'imei': '',
            'Content-Type': 'application/json',
            'token': parse.data.data.token
          }
        }
      ).then(function (response){

        console.log(response);
        that.dataList=response.data.data;
      // eslint-disable-next-line no-unused-vars
    }).catch(function (error){

    })

 

 

 

定义头部

 

 

 

 

 

get请求

    headersFData.headers.token=parse.data.data.token;
    // eslint-disable-next-line no-unused-vars
    axios.get("http://127.0.0.1:9000/dev/app/tasks", {
      headers:headersFData.headers,
      params: {
        type: "TASK",
        range: "all",
        planStartTimeStat: getStartDate(),
        planStartTimeEnd: getEndDate()
      }
    }, headersFData).then(function (response) {
      console.log(JSON.stringify(response))
      // eslint-disable-next-line no-unused-vars
    }).catch(function (error) {
      console.log(error);
    })

 

posted @ 2022-03-23 17:19  笑~笑  阅读(212)  评论(0)    收藏  举报