export const add = (data) => { return axios.post(`${API_URL}/board/add.html`, (data)) .then(response => response.data) .catch(error => { throw error; }); }; 当前接口后端拿不到传递的数据
时间: 2024-02-27 17:57:36 浏览: 73
您好,根据您提供的代码,似乎是将数据作为一个对象传递给了 `axios.post` 方法,但是在后端却无法获取到数据。可能是因为在发送请求时,数据需要以 `application/json` 的格式传递,而您的代码中未指定请求头。您可以尝试在 `axios.post` 方法中加入如下代码来指定请求头:
```
axios.post(`${API_URL}/board/add.html`, data, { headers: { 'Content-Type': 'application/json' } })
```
这样就可以确保数据以正确的格式传递给后端了。同时,您也可以在后端中添加相应的处理来接收传递过来的数据。
相关问题
怎么在vue3中使用此函数import { post,get } from "./request"; export const GetOEEDetail=data=>{ return post({ url:"api/auy/auyfaymanAdd", data }) } export const GetEmpNameByEmpNo =data=>{ return post({ url:"/api/Report/GetOEEDetail", data }) }
在Vue 3中使用这个函数,你需要先在你的项目中创建一个名为`request.js`的文件,并将以下代码复制到该文件中:
```javascript
import axios from 'axios';
export const post = async ({ url, data }) => {
try {
const response = await axios.post(url, data);
return response.data;
} catch (error) {
console.error(error);
throw error;
}
};
export const get = async ({ url, params }) => {
try {
const response = await axios.get(url, { params });
return response.data;
} catch (error) {
console.error(error);
throw error;
}
};
```
然后,在你需要使用这些函数的地方,可以通过以下方式导入和使用:
```javascript
import { post, get } from "./request";
export const GetOEEDetail = async (data) => {
return post({
url: "api/auy/auyfaymanAdd",
data
});
};
export const GetEmpNameByEmpNo = async (data) => {
return post({
url: "/api/Report/GetOEEDetail",
data
});
};
```
这样你就可以在Vue 3项目中使用这些函数了。记得确保在使用这些函数之前安装`axios`依赖项,可以通过运行以下命令来安装:
```
npm install axios
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)