gyf-mock
v1.0.0
Published
@ ```js //数据 ./mock/data.json [{"name": "zhangsan", "password": 123456}]
Downloads
1
Readme
@
//数据 ./mock/data.json
[{"name": "zhangsan", "password": 123456}]
//mock 代码
const Mock = require('mockjs');
const fs = require('fs');
let data = Mock.mock({
'list|1-10': [{
"user": "@cname"
}]
})
console.log(data.list);
fs.writeFileSync('data.json', JSON.stringify(data.list))
//public文件夹 里面有CSS JS
//js代码
axios.post('/api/getData').then(({ data }) => {
document.body.innerHTML = data.map(item => {
return `<p>${item.user}</p>`
}).join('');
})
//html 2个链接代码
<script src="./js/axios.js"></script>
<script src="./js/index.js"></script>
//app。js代码
const express = require('express');
const app = express();
app.listen(8000, () => {
console.log('服务器已启动');
})
app.use(express.static('public'));
app.use(express.json());
app.post('/api/getData', (req, res) => {
let data = require('./mock/data.json');
res.send(data)
})
//下载express axios mack