無狀態(tài)組件的useState與useEffect用法
const [states, setStates] = useState({
data1:[],
data2:[],
data3:[],
data4:[],
})
function getlist() {
return Getlist.getlist({ product_category: "5dc2a1aea65d993beb14a199" })
}
function getlist2() {
return Getlist.getlist({ product_category: "5dd52a59f491100db9242811" })
}
useEffect(() => {
axios.all([getlist(), getlist2()]).then(axios.spread((res1, res2) => {
setStates({
data1: res1.data.products,
data2:res2.data.products
})
}))
})