Skip to content

Commit b888044

Browse files
committed
Feat: Set Routes for application
1 parent e73b71c commit b888044

File tree

9 files changed

+116
-57
lines changed

9 files changed

+116
-57
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
},
1010
"dependencies": {
1111
"@vant/touch-emulator": "^1.3.2",
12+
"nprogress": "^0.2.0",
1213
"pinia": "^2.0.14",
1314
"vant": "^3.4.9",
1415
"vconsole": "^3.14.6",
15-
"vue": "^3.2.25"
16+
"vue": "^3.2.25",
17+
"vue-router": "^4.0.15"
1618
},
1719
"devDependencies": {
20+
"@types/nprogress": "^0.2.0",
1821
"@vitejs/plugin-vue": "^2.3.3",
1922
"less": "^4.1.2",
2023
"postcss-preset-env": "^7.6.0",

src/App.vue

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
<script setup lang="ts">
2-
// This starter template is using Vue 3 <script setup> SFCs
3-
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
4-
import HelloWorld from './components/HelloWorld.vue'
5-
</script>
6-
71
<template>
8-
<img alt="Vue logo" src="./assets/logo.png" />
9-
<HelloWorld msg="Hello Vue 3 + TypeScript + Vite" />
2+
<router-view />
103
</template>
11-
12-
<style>
13-
#app {
14-
font-family: Avenir, Helvetica, Arial, sans-serif;
15-
-webkit-font-smoothing: antialiased;
16-
-moz-osx-font-smoothing: grayscale;
17-
text-align: center;
18-
color: #2c3e50;
19-
margin-top: 60px;
20-
}
21-
</style>

src/assets/logo.png

-1.2 KB
Loading

src/components/HelloWorld.vue

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createApp } from 'vue'
22
import App from './App.vue'
3+
import router from './router'
34
import { createPinia } from 'pinia'
45

56
// Vant 桌面端适配
@@ -16,7 +17,11 @@ const vConsole = new VConsole({ theme: 'dark' })
1617
// vite-plugin-vconsole 社区版
1718
// https://github.com/vadxq/vite-plugin-vconsole
1819

19-
createApp(App)
20+
const app = createApp(App)
21+
22+
app
23+
.use(router)
2024
.use(createPinia())
2125
.use(Button)
22-
.mount('#app')
26+
27+
app.mount('#app')

src/router/index.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
import { createRouter, createWebHistory } from 'vue-router'
3+
import NProgress from 'nprogress'
4+
import 'nprogress/nprogress.css'
5+
NProgress.configure({ showSpinner: true })
6+
7+
// 导入路由组件
8+
import Dashboard from '../views/dashboard/analysis/index.vue'
9+
import Workplace from '../views/dashboard/workplace/index.vue'
10+
11+
// 定义路由,每个路由都需要映射到一个组件
12+
const routes = [
13+
{
14+
path: '/',
15+
name: 'dashboard',
16+
component: Dashboard
17+
}, {
18+
path: '/workplace',
19+
name: 'workplace',
20+
component: Workplace
21+
}
22+
]
23+
24+
// 创建路由实例并传递 `routes` 配置
25+
const router = createRouter({
26+
history: createWebHistory(),
27+
routes
28+
})
29+
30+
router.beforeEach((_to, _from, next) => {
31+
NProgress.start(); // start progress bar
32+
next()
33+
})
34+
35+
router.afterEach(() => {
36+
NProgress.done() // finish progress bar
37+
})
38+
39+
// 导出路由实例,并在 `main.ts` 挂载
40+
export default router
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<div class="container">
3+
<img class="logo" src="../../../assets/logo.png" alt="logo" />
4+
<router-link to="/workplace">进入工作区</router-link>
5+
</div>
6+
</template>
7+
8+
<script setup lang="ts">
9+
</script>
10+
11+
<style lang="less" scoped>
12+
.container {
13+
width: 100vw;
14+
height: 100vh;
15+
display: flex;
16+
flex-direction: column;
17+
align-items: center;
18+
justify-content: center;
19+
position: relative;
20+
21+
.logo {
22+
width: 80px;
23+
height: 80px;
24+
}
25+
}
26+
</style>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<template>
2+
<div class="container">
3+
工作区
4+
</div>
5+
</template>
6+
7+
<script setup lang="ts">
8+
</script>
9+
10+
<style lang="less" scoped>
11+
.container {
12+
width: 100vw;
13+
height: 100vh;
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
justify-content: center;
18+
position: relative;
19+
}
20+
</style>

yarn.lock

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@
112112
estree-walker "^2.0.1"
113113
picomatch "^2.2.2"
114114

115+
"@types/nprogress@^0.2.0":
116+
version "0.2.0"
117+
resolved "https://registry.yarnpkg.com/@types/nprogress/-/nprogress-0.2.0.tgz#86c593682d4199212a0509cc3c4d562bbbd6e45f"
118+
integrity sha512-1cYJrqq9GezNFPsWTZpFut/d4CjpZqA0vhqDUPFWYKF1oIyBz5qnoYMzR+0C/T96t3ebLAC1SSnwrVOm5/j74A==
119+
115120
"@vant/icons@^1.8.0":
116121
version "1.8.0"
117122
resolved "https://registry.yarnpkg.com/@vant/icons/-/icons-1.8.0.tgz#36b13f2e628b533f6523a93a168cf02f07056674"
@@ -215,7 +220,7 @@
215220
"@vue/compiler-dom" "3.2.36"
216221
"@vue/shared" "3.2.36"
217222

218-
"@vue/devtools-api@^6.1.4":
223+
"@vue/devtools-api@^6.0.0", "@vue/devtools-api@^6.1.4":
219224
version "6.1.4"
220225
resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.1.4.tgz#b4aec2f4b4599e11ba774a50c67fa378c9824e53"
221226
integrity sha512-IiA0SvDrJEgXvVxjNkHPFfDx6SXw0b/TUkqMcDZWNg9fnCAHbTpoo59YfJ9QLFkwa3raau5vSlRVzMSLDnfdtQ==
@@ -739,6 +744,11 @@ normalize-range@^0.1.2:
739744
resolved "https://registry.yarnpkg.com/normalize-range/-/normalize-range-0.1.2.tgz#2d10c06bdfd312ea9777695a4d28439456b75942"
740745
integrity sha1-LRDAa9/TEuqXd2laTShDlFa3WUI=
741746

747+
nprogress@^0.2.0:
748+
version "0.2.0"
749+
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
750+
integrity sha1-y480xTIT2JVyP8urkH6UIq28r7E=
751+
742752
object-assign@>=4.0.1:
743753
version "4.1.1"
744754
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
@@ -1222,6 +1232,13 @@ vue-demi@*:
12221232
resolved "https://registry.yarnpkg.com/vue-demi/-/vue-demi-0.12.5.tgz#8eeed566a7d86eb090209a11723f887d28aeb2d1"
12231233
integrity sha512-BREuTgTYlUr0zw0EZn3hnhC3I6gPWv+Kwh4MCih6QcAeaTlaIX0DwOVN0wHej7hSvDPecz4jygy/idsgKfW58Q==
12241234

1235+
vue-router@^4.0.15:
1236+
version "4.0.15"
1237+
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.15.tgz#b4a0661efe197f8c724e0f233308f8776e2c3667"
1238+
integrity sha512-xa+pIN9ZqORdIW1MkN2+d9Ui2pCM1b/UMgwYUCZOiFYHAvz/slKKBDha8DLrh5aCG/RibtrpyhKjKOZ85tYyWg==
1239+
dependencies:
1240+
"@vue/devtools-api" "^6.0.0"
1241+
12251242
vue-tsc@^0.34.7:
12261243
version "0.34.16"
12271244
resolved "https://registry.yarnpkg.com/vue-tsc/-/vue-tsc-0.34.16.tgz#92cc8cc23bc3e979d44bc8ed9a318d46ee5201fa"

0 commit comments

Comments
 (0)