vue-cli-plugin-xg-mock
v1.0.2
Published
vue-cli plugin to add mock
Downloads
31
Readme
版本说明
版本 | 说明
---|---
1.x | 版本不再安装axios,仅安装mockjs
0.x | 版本同时安装mockjs和axios,以及示例
插件作用
vue-cli插件,给vue-cli项目添加本地接口调试返回mock数据,以便在后端未提供接口时更好的实现业务逻辑
安装插件时会同时安装mockjs和axios
添加插件
vue add vue-cli-plugin-xg-mock
文件说明
插件添加成功后,会在项目根目录生成以下文件,注意!如果已存在相同文件,则会替换原文件,文件夹则会合并
template
├─mock
│ ├─ index.js // 定义接口路由和返回mock数据,我们的接口都在这里配置
│ └─ mock-server.js // 路由挂载,一般不需要修改
│
└─src // 1.x版本没有此文件夹
├─api // 页面请求统一存放在这里
│ └─ index.js
│
├─demo
│ └─ MockTest.vue // 一个请求例子
│
└─util
└─ axios-config.js // axios请求封装
可以把MockTest.vue例子作为一个子组件在任何页面中引入,测试请求是否成功。
注:插件安装后,以上除了mock文件夹的文件外,其他文件可根据自身项目删除不需要的文件。