添加mock
This commit is contained in:
parent
399e337ebf
commit
1c4dc4fa6e
52
mock/user.mock.ts
Normal file
52
mock/user.mock.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { MockHandler } from 'vite-plugin-mock-server'
|
||||
type UserModel = {
|
||||
username: string;
|
||||
password: string;
|
||||
avatar: string;
|
||||
}
|
||||
type LoginUserModel = {
|
||||
token: string;
|
||||
user: UserModel;
|
||||
}
|
||||
const loginUserList: LoginUserModel[] = []
|
||||
|
||||
const userMock: MockHandler[] = [
|
||||
{
|
||||
pattern: '/api/user/login',
|
||||
method:'POST',
|
||||
handle: (req, res) => {
|
||||
const data = { code: 1 }
|
||||
res.end(JSON.stringify(data))
|
||||
}
|
||||
},
|
||||
{
|
||||
pattern: '/api/test1/*',
|
||||
handle: (req, res) => {
|
||||
res.end('Hello world!' + req.url)
|
||||
}
|
||||
},
|
||||
{
|
||||
pattern: '/api/test1/users/{userId}',
|
||||
handle: (req, res, pathVars) => {
|
||||
const data = {
|
||||
url: req.url,
|
||||
pathVars: pathVars
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json')
|
||||
res.end(JSON.stringify(data))
|
||||
}
|
||||
},
|
||||
{
|
||||
pattern: '/api/test1/users/{userId}/{blogId}',
|
||||
handle: (req, res, pathVars) => {
|
||||
const data = {
|
||||
url: req.url,
|
||||
pathVars: pathVars
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/json')
|
||||
res.end(JSON.stringify(data))
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
export default userMock
|
796
package-lock.json
generated
796
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,8 @@
|
||||
"type-check": "vue-tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.3.4",
|
||||
"less": "^4.1.3",
|
||||
"pinia": "^2.0.32",
|
||||
"vue": "^3.2.47",
|
||||
"vue-router": "^4.1.6"
|
||||
@ -22,6 +24,7 @@
|
||||
"npm-run-all": "^4.1.5",
|
||||
"typescript": "~4.7.4",
|
||||
"vite": "^4.1.3",
|
||||
"vite-plugin-mock-server": "^1.0.4",
|
||||
"vue-tsc": "^1.1.5"
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import HelloWorld from './components/HelloWorld.vue'
|
||||
|
||||
<div class="wrapper">
|
||||
<HelloWorld msg="You did it!" />
|
||||
|
||||
|
||||
<nav>
|
||||
<RouterLink to="/">Home</RouterLink>
|
||||
<RouterLink to="/about">About</RouterLink>
|
||||
|
5
src/components/Intro.vue
Normal file
5
src/components/Intro.vue
Normal file
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
<script setup lang="ts"></script>
|
||||
<style></style>
|
@ -3,10 +3,16 @@ import { fileURLToPath, URL } from 'node:url'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import mockServer from 'vite-plugin-mock-server'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue(), vueJsx()],
|
||||
plugins: [
|
||||
vue(),
|
||||
vueJsx(),
|
||||
mockServer({
|
||||
mockRootDir: './mock'
|
||||
})],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
|
Loading…
x
Reference in New Issue
Block a user