mockjs的get传参 前端请求 const { data } = await axios("/video/childcomments", {params: {sort: 1,start: 2,count: 5,childCount: 6,commenIndex: 0,},}); 后端获取参数 使用正则匹配url /*** # 根据url获取query参数* @param {Url} urlStr get请求获取参数 eg:"/video/childcomments?sort=1&start=2&count=5&childCount=14&commenIndex=0"* @returns Object*/ const getQuery = urlStr => {const startIndex = urlStr.indexOf('?');const strSub = urlStr.substring(startIndex + 1);const strReplace = strSub.replaceAll('=', '":');const arr = strReplace.split('&');arr.forEach((it, i) => arr[i] = '"' + it);const arrToStr = arr.join(',')const resStr = `{${arrToStr}}`const resObj = JSON.parse(resStr); resObjreturn resObj }Mock.mock(/video\/childcomments.*?/, getInfo => {const { url } = getInfoconst toObj = getQuery( url)console.log(toObj); }) 执行结果