作者:手机用户2602903963 | 来源:互联网 | 2023-09-16 17:02
import axios from 'axios'
const baseUrl = 'http://localhost:3001/persons';
const getAll = () => {
return axios.get(baseUrl);
}
const create = (newObject) => {
return axios.post(baseUrl,newObject);
}
export default {
getAll:getAll,
create:create
}
使用 axios 从服务器获取数据(在来自 json 服务器的 reactjs 中),一切正常,但控制台显示此警告:
Line 13:1: Assign object to a variable before exporting as module default.
如何删除此警告?
回答
您需要先将对象分配给变量,然后再将其导出为默认值。
const exportedObject = {
getAll,
create,
};
export default exportedObject;