Skip to content

Commit

Permalink
feat: support post restful close #7
Browse files Browse the repository at this point in the history
  • Loading branch information
vben-admin committed Mar 10, 2021
1 parent b1298b1 commit 70b51e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
16 changes: 16 additions & 0 deletions examples/ts-example/mock/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,20 @@ export default [
};
},
},
{
url: '/api/testRestful/:id',
method: 'post',
response: ({ query, body }) => {
console.log('query>>>>>>>>', query);
console.log('query>>>>>>>>', body);
return {
code: 0,
message: 'ok',
data: {
roleName: 'admin',
roleValue: 'admin',
},
};
},
},
] as MockMethod[];
12 changes: 11 additions & 1 deletion examples/ts-example/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
<button @click="testPostFormData"> test post form-data</button>

<br />
<button @click="testRestful"> test restful</button>
<button @click="testRestful"> test get restful</button>

<br />
<button @click="testPostRestful"> test post restful</button>
</div>
</template>

Expand Down Expand Up @@ -55,11 +58,18 @@
});
};
const testPostRestful = () => {
axios.post('/api/testRestful/1').then((res) => {
console.log(res);
});
};
return {
getRoleById,
createUser,
testPostFormData,
testRestful,
testPostRestful,
};
},
});
Expand Down
10 changes: 8 additions & 2 deletions src/createMockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ export async function requestMiddle(opt: ViteMockOptions) {
const urlMatch = match(url, { decode: decodeURIComponent });

let query = queryParams.query;
if (reqUrl && JSON.stringify(query) == '{}') {
query = (urlMatch(reqUrl) as any).params || {};
if (reqUrl) {
if (isGet) {
if (JSON.stringify(query) === '{}') {
query = (urlMatch(reqUrl) as any).params || {};
}
} else {
query = (urlMatch(reqUrl) as any).params || {};
}
}

const body = (await parseJson(req)) as Record<string, any>;
Expand Down

0 comments on commit 70b51e8

Please sign in to comment.