使用的版本信息
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); })