zoukankan      html  css  js  c++  java
  • mock数据

    JSON-Server 是一个 Node 模块,运行 Express 服务器,你可以指定一个 json 文件作为请求的数据源。

    安装:

    npm install json-server --save

    创建数据文件:

    数据文件(外层需要加一层ReportDetail):

    {
        "ReportDetail": 
        {
            "errno": 0,
            "errmsg": "success",
            "data": {
                "content": "",
                "roadname": "",
                "contact": "",
                "time": "2020-05-07 15:09",
                "status": "u5f85u5b8cu5584",
                "color": 1,
                "event": "u7981u884cu6807u5fd7u62a5u9519",
                "parent_type": "15",
                "resubmit_flag": 1,
                "supply": 1,
                "image_url": "http://pics5.baidu.com/feed/9a504fc2d562853532e7bec5c61077c1a5ef63d1.jpeg?token=bddb1bc34b845756c0ce20b2580ea57b",
                "audit_detail": [{
                    "time": "2020-05-07 15:09",
                    "describe": "u8bf7u5b8cu5584u7167u7247u6216u8005u8be6u7ec6u63cfu8ff0u540eu518du6b21u63d0u4ea4u3002"
                }],
                "event_help": 0,
                "useful": 0,
                "useless": 0,
                "video_info": [],
                "life_time": "u8d85u8fc71u5929",
                "display_type": 0,
                "commentlist": [],
                "interact_num": 0,
                "start_point": "12948121,4845160",
                "start_name": "信息路",
                "end_point": "12948432,4845543",
                "end_name": "石化路",
                "point": "12948121,4845160",
                "address": "杏石口路"
            }
        }
    }

     在package.json里设置:

    "scripts": {
        "dev:mock": "npm run mock & NODE_ENV=dev npm run dev",
        "mock": "json-server --watch src/mock/data.json",
        ......
      },

    vue.config.js里需要配置:

    module.exports = {
        devServer: {
            proxy: {
                '/mock': {
                    target: 'http://localhost:3000/',
                    changeOrigin: true,
                    pathRewrite: {
                        '^/mock': ''
                    }
                }
            }
        },
    };

    请求配置:

    ReportDetail: {
            method: 'post',
            url: '/mock/ReportDetail',
    },

    执行:

    nom run dev:mock

    响应接口的请求会获取到数据文件里配置的数据。

  • 相关阅读:
    qbzt day6 上午
    qbzt day5 下午
    qbzt day5 上午
    【7.24校内交流赛】T3【qbxt】复读警告
    【7.24校内交流赛】T1&T2
    一个一定要好好提溜出来的贪心题
    7.19 讲题
    DP大大大大大赏
    图论经典例题大赏
    数据结构题大赏
  • 原文地址:https://www.cnblogs.com/xjy20170907/p/13631737.html
Copyright © 2011-2022 走看看