如何划分从axios导入的对象数量?



关于导入数据,Axios会带入100条,是否可以将100条中的20条单独放入到Axios或useState中?我想知道是否还有其他方法。

我想知道除了使用rowum>=20作为查询语句之外,是否还有其他方法。

const [list, setList] = useState([]);

useEffect(() => {
axios.get('http://localhost:8080/movielist/getMovieList_boxoffice')
.then(res => {setList(res.data)})
.catch(err => console.log(err))
},[already_released]);

{
list.map ((item, index) => {
return (

<ol>
<li>objectnum = {index+1}</li>
</ol>

)
})
}

const [list, setList] = useState([0,20]);

useEffect(() => {
axios.get('http://localhost:8080/movielist/getMovieList_boxoffice')
.then(res => {setList(res.data)})
.catch(err => console.log(err))
},[already_released]);

{
list.map ((item, index(21)) => {
var arr = index
var arr1 = index(0,21)
return (
<div>
<ol>
<li>objectnum = {arr1+1}</li>
</ol>
</div>
)
})
}

您可以使用splice只保留数据的前20项:res.data.splice(20))

在你的例子中:

useEffect(() => {
axios.get('http://localhost:8080/movielist/getMovieList_boxoffice')
.then(res => {setList(res.data.splice(20))})
.catch(err => console.log(err))
},[already_released]);

最新更新