安装 npm install mockjs
1.创建mock.js
const Mock = require('mockjs'); // mock一组数据 const deptList = ['内科一病区', '骨科一病区', '内科二病区', '骨科二病区', '内科二病区', '骨科二病区',] const deptDrugDate = function () { let articles = []; for (let i = 0; i < 4; i++) { let newArticleObje = { execDeptName: deptList[i], itemName: drugNameList[i], hospitalName: "基层云医疗", itemSpec: drugSpecList[i], UNIT: unitList[i], PRICE: priceList[i], AMOUNT: amountList[i], COSTS: priceList[i] * amountList[i], } articles.push(newArticleObje); } return { Details: articles, Master: { beginDate: "2021-01-05", date: "2021-01-05 15:42", endDate: "2021-01-05", operName: "鄢宁", hospitalName: "基层云医疗", costs: 0, } } } // 需要几个接口就定义几个function, //Mock.mock(url(接口地址),method(接口方式),上面定义的数据); Mock.mock('/deptDrug', 'post', deptDrugDate);
2.在main.js里面进行全局引用注册
require('./mock/mock.js');
3.在.vue文件正常使用即可
axios.post('/deptDrug').then((res) => { console.log(res) })