報錯信息:
GET http://localhost:8081/user/findPage?pageNum=1%20&%20pageSize=2 400
問題原因:
fetch("http://localhost:8081/user/findPage?pageNum=1 & pageSize=2").then(res => res.json()).then(res => {})
在url路徑中我在 pageNum=1 & pageSize=2 的&前后兩段打了空格,導致請求路徑中多了兩個字符串:%20
解決方法:
將&前后兩段空格刪掉就可以了
// 請求分頁查詢數據 fetch api 有以下幾個參數,第一個參數是url
// .then 返回一個res,之后對他進行一個json的處理,因為他返回的res是一個字符串,需要把字符串轉成json
// 通過res.json()函數 這個方法,把他轉成json,再.then 這個res就是json類型的了
fetch("http://localhost:8081/user/findPage?pageNum=1&pageSize=2").then(res => res.json()).then(res => {
console.log(res)
this.tableData = res.data
this.total = res.total
})