mock數據的使用方法


安裝  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)
      })

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM