diff --git a/admin-fe/README.MD b/admin-fe/README.MD index 4b82973..8c5dcfc 100644 --- a/admin-fe/README.MD +++ b/admin-fe/README.MD @@ -158,10 +158,24 @@ const router = createRouter({ const app = createApp(); app.use(router); // 在应用使用router ``` + 显示路由及跳转 + ```vue + -``` \ No newline at end of file +``` + +### 前端分离的接口交互 + +#### 1.跨域 + +协议、访问域、端口只有一个不同都是跨域. + +协议: http/https 端口: 冒号后面的数字 +> 跨域除了上述原则之外,自定义请求头也会使跨域失败 + +#### 请求接口 diff --git a/admin-fe/src/App.vue b/admin-fe/src/App.vue index 71cd281..014dcaf 100644 --- a/admin-fe/src/App.vue +++ b/admin-fe/src/App.vue @@ -1,30 +1,16 @@ diff --git a/admin-fe/src/User.vue b/admin-fe/src/User.vue deleted file mode 100644 index 82c3a1d..0000000 --- a/admin-fe/src/User.vue +++ /dev/null @@ -1,14 +0,0 @@ - - - - - \ No newline at end of file diff --git a/admin-fe/src/assets/app.css b/admin-fe/src/assets/app.css new file mode 100644 index 0000000..d81191c --- /dev/null +++ b/admin-fe/src/assets/app.css @@ -0,0 +1,19 @@ +:root { + --primary-color: #fff; + --primary-color-text: #333; + --font-size: 14px; +} + +* { + margin: 0; + padding: 0; +} + +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, 'Source Han Sans SC', 'Microsoft YaHei', 'Microsoft YaHei UI', "Helvetica Neue", sans-serif; + scroll-behavior: smooth; +} +.container{ + max-width: 1200px; + margin: auto; +} diff --git a/admin-fe/src/main.ts b/admin-fe/src/main.ts index bad7cdc..11f5de3 100644 --- a/admin-fe/src/main.ts +++ b/admin-fe/src/main.ts @@ -1,6 +1,10 @@ import {createApp} from 'vue'; import App from './App.vue' import router from './router' +import {httpConfig} from "./util/http"; + + +httpConfig.baseURL = "http://localhost:8080" const app = createApp(App) // 使用路由 diff --git a/admin-fe/src/router/routes.ts b/admin-fe/src/router/routes.ts index e231749..543d9d1 100644 --- a/admin-fe/src/router/routes.ts +++ b/admin-fe/src/router/routes.ts @@ -1,6 +1,7 @@ import {RouteRecordRaw} from "vue-router"; -import Home from './../Home.vue' -import User from './../User.vue' +import Home from '../views/admin/Home.vue' +import Login from '../views/Login.vue' +import NotFound from '../views/NotFound.vue' const routes: RouteRecordRaw[] = [ { @@ -8,8 +9,12 @@ const routes: RouteRecordRaw[] = [ component: Home }, { - path: '/user', - component: User + path: '/login', + component: Login + }, + { + path:'/:pathMatch(.*)*', + component: NotFound } ] diff --git a/admin-fe/src/util/http.ts b/admin-fe/src/util/http.ts new file mode 100644 index 0000000..d0fc47a --- /dev/null +++ b/admin-fe/src/util/http.ts @@ -0,0 +1,41 @@ +export type HttpMethod = 'get' | 'post' | 'delete' | 'put' + +export const httpConfig = { + baseURL: '' +} +export type ResponseModel = { + code: number + message: string + data: T + trace?: string +} + +class Http { + post(url, data) { + return this.request(url, 'post', data) + } + + request(url: string, method: HttpMethod, data: any = null) { + return new Promise>((resolve, reject) => { + + fetch(httpConfig.baseURL + url, { + method, + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json;charset=utf-8' + } + }) + .then(res => res.json()) // 只要json的响应数据 + .then((res: ResponseModel) => { + if (res.code !== 0) { + reject(Error(res.message)) + return; + } + resolve(res.data) + }).catch(reject) + }); + } +} + +const http = new Http(); +export default http \ No newline at end of file diff --git a/admin-fe/src/views/Login.vue b/admin-fe/src/views/Login.vue new file mode 100644 index 0000000..7c4efd6 --- /dev/null +++ b/admin-fe/src/views/Login.vue @@ -0,0 +1,51 @@ + + + + + \ No newline at end of file diff --git a/admin-fe/src/views/NotFound.vue b/admin-fe/src/views/NotFound.vue new file mode 100644 index 0000000..9f9a491 --- /dev/null +++ b/admin-fe/src/views/NotFound.vue @@ -0,0 +1,18 @@ + + + + + \ No newline at end of file diff --git a/admin-fe/src/Home.vue b/admin-fe/src/views/admin/Home.vue similarity index 100% rename from admin-fe/src/Home.vue rename to admin-fe/src/views/admin/Home.vue