<file_sep>#模拟数据

1. `mockData`模拟数据文件夹，可在该文件夹下创建多个json数据

2. `src/server.js`服务启动文件,可修改服务端口
  
   监听端口 `prot`可随意修改
   >```javascript
   >const port = 22222
   >app.listen(port, () => 
   >    console.log(`本机服务已启动>>> http://${getIP()}:${port}`)
   >);
   >```
   
3. 启动项目

   ```shell
   # 同步依赖
   npm install
   # 启动项目
   npm run serve
   ```
4. 数据请求访问连接该项目ip和端口，访问需要模拟数据的文件名即可

   `server.js`已对`method`做定向，目前只测试到`get`、`post`请求方法可用
   
   axios框架示例
   >```javascript
   >axios.get('/data.json')
   >axios.post('/data.json')
   >```# mock
# mock
<file_sep>function cross (app) {
    /*跨域解决*/
    app.all('*', function (req, res, next) {
        res.header('Access-Control-Allow-Origin', req.headers.origin);//获取请求源 这样所有请求就都有访问权限了
        res.header('Access-Control-Allow-Credentials', true);
        res.header('Access-Control-Allow-Headers', 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With')
        res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS');
        res.header('Content-Type', 'application/json;charset=utf-8');
        next()
    });
}

module.exports = cross<file_sep>const path = require('path');
const getIP = require('./utils/getIP');
const express = require('express');
const app = new express();
const cross = require('./utils/cross');

/*跨域*/
cross(app);

/*对method做定向*/
app.use((req, res, next) => (req.method = 'GET') && next());

/*静态文件*/
app.use('/', express.static(path.resolve(__dirname, '..', './mockData')));

/*监听端口*/
const port = 22222;
app.listen(port, () =>
    console.log(`本机服务已启动>>> http://${getIP()}:${port}`)
);