一個坑?response 不配置會顯示接口調用成功,有返回數(shù)據(jù),但是不渲染頁面
- -、真奇怪,老師演示的代碼沒有配置為什么會渲染
```js
let?table?=?layui.table; table.render({ ????elem:?'#customerList',?//?table的id ????url:?'/customer/list',?//?數(shù)據(jù)接口 ????page:?true,??//開啟分頁 ????response:{?//?這個不配置,不會渲染 ????????statusName:'code',? ????????statusCode:200? ????}, ????parseData:?function?(res)?{?//res?即為原始返回的數(shù)據(jù) ????????return?{ ????????????"code":?res.code,?//解析接口狀態(tài) ????????????"msg":?res.msg,?//解析提示文本 ????????????"count":?res.data.count,?//解析數(shù)據(jù)長度 ????????????"data":?res.data.records?//解析數(shù)據(jù)列表 ????????}; ????}, ????cols:?[[?//?表頭 ????????{field:?'realName',?title:?'真實姓名'}, ????????{field:?'sex',?title:?'性別'}, ????????{field:?'age',?title:?'年齡'}, ????????{field:?'phone',?title:?'手機號碼'}, ????????{field:?'createTime',?title:?'創(chuàng)建時間'}, ????????{title:?'操作',?toolbar:?'#barDemo'} ????]] });
```
2022-02-06
此段代碼中的code值,直接定義為0,否則layui認為數(shù)據(jù)請求失敗。
即: