yyq-pagedemo
v1.0.0
Published
```js const express=require('express'); const app=express(); const fs=require('fs'); app.listen(8888,()=>console.log('开启')) app.use(express.static('public')) app.set('view engine',"ejs") app.get('/',(req,res)=>{ res.render('index') })
Downloads
3
Readme
const express=require('express');
const app=express();
const fs=require('fs');
app.listen(8888,()=>console.log('开启'))
app.use(express.static('public'))
app.set('view engine',"ejs")
app.get('/',(req,res)=>{
res.render('index')
})
app.get('/detail',(req,res)=>{
let{id}=req.query;
let data=JSON.parse(fs.readFileSync('mock/user.json'))
let obj=data.find(item=>+item.id===+id)
res.render('detail',obj)
})
app.get('/api/page',(req,res)=>{
let{index,num}=req.query;
fs.readFile('mock/user.json',(err,data)=>{
if(err){
res.send({code:0})
return;
}
data=JSON.parse(data);
res.send({
code:1,
arr:data.slice(index*num,(+index+1)*num),
max:Math.ceil(data.length/num)
})
})
})