url路径参数提取
一、url路径参数提取
Mock.mock(
//要拦截的url:http://localhost:8080/get/data?type=$%GDR(&^TGKJHG
RegExp('/get/data/*'),
"get",
(options) =>{
//将url中的type参数的值提取出来
let param = Mock.getQuery(options.url,"type");
//将乱码的type转为中文
let type = decodeURIComponent(param);
let template = {};
//根据参数不同的值返回不同的结果
if(type=="参数1"){
template = {"code":0,"msg":null,"data":{"data":[]}}
}else if(type=="参数2"){
template = {"code":0,"msg":null,"data":{"data":[]}}
}else if(type=="参数3"){
template =
{"code":0,"msg":null,"data":{"data":[],"xData":[]}}
}
return template;
}
)