mockjs:可以起一个mockjs的serve,也可以配置在本地
main.js:require('mockjs')
新建list-mock.js:
const Mock=require("mockjs")
const Random=Mock.Random
const produceList=function(){
let list=[]
for (let i=0;i<10;i++) {
let listObject={
date: Random.date(),
name: Random.cname(),
address: Mock.mock('@county(true)')
}
list.push(listObject)
}
return list
}
Mock.mock('/list','get',produceList)
axios-mock-adapter 配置
mock文档下新建index.js
import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'
let mock=new MockAdapter(axios)
mock.onGet('/list').reply(200,[
{date: '2016-05-01',name: '王小虎',address: '上海市普陀区金沙江路 1519 弄' },
])
调用方式:
require('../mock/list-mock.js')
//require('../mock/index.js')
this.$axios.get('/list').then(({data})=>{
this.tableData=data
}).catch(err=>{
console.log(err)
})