修改vue.config.js文件中的proxy,匹配線上接口中所有包含v1字段的接口枪眉,重寫到線上接口亦渗,其他不匹配的繼續(xù)走mock
注意引用mock數(shù)據(jù),是after... ,把before改成after巴粪,因?yàn)檫@個(gè)問題改的生無可戀懷疑人生ing...
proxy: {
'/v1': {
target: https://bsxq.whiteplanet.com.cn/
,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
},
},
after: require('./mock/mock-server.js'),
判斷一個(gè)對(duì)象是否為空
Object.keys(obj).length==0
mock數(shù)據(jù)的使用
以約診管理為例
1.在api/下新增appointment.js文件哨鸭,
import request from '@/utils/request'
export function getList(params) {
return request({
url: '/vue-admin-template/appointment/list',
method: 'get',
params
})
}
2.在mock/中增加同名文件
數(shù)據(jù)略
3民宿,重點(diǎn),要引入M玫勘高!在mock/index.js中要先引入你編寫的文件
const appointment=require('./appointment')
const mocks = [
...appointment
]