![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/fe81ff1a7485432a94168f8ed9de8486.png)
官网: http://mockjs.com/
安装 npm install mockjs -D
steps1: main.js 文件引入
import '@/api/mock.js'
steps2: src/api/mock.js
import Mock from 'mockjs'
import homeApi from './mockData/home'
Mock.mock(/api\/home\/getTableData/, 'get', homeApi.getTableData)
steps3: 编造数据
src/api/mockData/home.js
export default {getTableData: () => {return {code: 200,data: {tableData: [{name: 'oppo',todayBuy: 500,monthBuy: 3500,totalBuy: 22000}]}}}
}
steps4: 页面发起请求
import axios from 'axios'
axios({url: '/api/home/getTableData',method: 'get'
}).then((res) => {const data = res.data.getTableDataif (data.code == 200) {tableData.value = data.data.tableData}
})