我是 React Js 或任何类型的 javascript 框架的新手。我在“onLoadServices”之外创建了一个“allServices”变量,在其中将数据传递给它,如下所示。问题是,当我在 de const onLoadService 中对其进行 console.log 时,它向我显示了整个对象,我也可以访问属性,但在外部它只显示了整个对象,但是当尝试访问属性时它失败了
let allServices = {
id: '',
client_id: '',
user_id: '',
status: "",
repair_value: "",
taxes: "",
service_code: "",
has_client_paid: "",
has_technician_paid: "",
plate: "",
brand: "",
model: "",
year: "",
color: "",
created_at: "",
updated_at: ""
};
const Dashboard = () => {
const classes = useStyles();
const [filters, setFilters] = useState({});
const [technicians, setTechnicians] = useState([]);
useEffect(() => {
onLoadSerivces();
onLoadTechnicians();
}, []);
useEffect(() => {
}, [filters]);
const onLoadSerivces = async () => {
try {
const { data } = await api.get(`/service`);
allServices = response.data.data
console.log("first log ", allServices[0])
}
catch (err) {
let error = JSON.stringify(err.message);
alert(error);
}
};
console.log("Second log ", allServices[0])
如果我尝试在没有 [0] 的情况下打印对象,它会在两个 console.logs 中显示相同的内容...问题出在属性上。
错误消息“TypeError:无法读取未定义的属性‘状态’”
我做错了什么?
catspeake
相关分类