mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-07 01:46:46 +08:00
接口初始化 第一版
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import {createProdMockServer} from 'vite-plugin-mock/es/createProdMockServer'
|
||||
|
||||
const context = import.meta.glob("./mocks/*.js", {eager: true})
|
||||
const API = await import("../api/api")
|
||||
const API = import.meta.glob("../api/api.js", {eager: true})
|
||||
const module = API['../api/api.js']
|
||||
const array = Object.keys(context).map(path =>
|
||||
Object.keys(context[path].default).map(url => ({
|
||||
url: API[url].split(' ')[0],
|
||||
method: API[url].split(' ').length > 1 ? API[url].split(' ')[1] : 'get',
|
||||
url: module[url].split(' ')[0],
|
||||
method: module[url].split(' ').length > 1 ? module[url].split(' ')[1] : 'get',
|
||||
response: context[path].default[url]
|
||||
}))).reduce((r, m) => [...r, ...m])
|
||||
console.log(array)
|
||||
createProdMockServer([...array])
|
||||
@@ -1,11 +1,11 @@
|
||||
const routes = [];
|
||||
const context =import.meta.glob("../views/*/*.vue")
|
||||
const context =import.meta.glob("../views/*/*.vue", {eager: true})
|
||||
Object.keys(context).forEach(path => {
|
||||
const componentName = path.replace(/.*\/([^\\.\\/]*)\.vue$/, '$1');
|
||||
routes.push({
|
||||
path: `/${componentName.toLowerCase()}`,
|
||||
name: componentName,
|
||||
component: () => import(path/* @vite-ignore */),
|
||||
component: context[path].default,
|
||||
meta: {
|
||||
isLink: true
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ export default defineConfig(({command}) =>
|
||||
}),
|
||||
viteMockServe({
|
||||
mockPath: './src/mock/mocks',
|
||||
injectCode: `
|
||||
console.log(111111111)
|
||||
`,
|
||||
// injectCode: `
|
||||
// console.log(111111111)
|
||||
// `,
|
||||
})
|
||||
],
|
||||
resolve: {
|
||||
|
||||
Reference in New Issue
Block a user