博主首页

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 @   笑~笑  阅读(201)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
历史上的今天:
2018-03-23 解决celipse中mybatis使用的时候xml没有提示的问题
2018-03-23 java里获取uuid
点击右上角即可分享
微信分享提示