From c6490526fe6f85a082c3185df63445daaa8ee0c0 Mon Sep 17 00:00:00 2001 From: "yingfeng.ai" Date: Mon, 4 Nov 2024 18:10:20 +0800 Subject: [PATCH] =?UTF-8?q?vue=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 学习VUE/hello_vue3/src/App.vue | 71 ++---------------- 学习VUE/hello_vue3/src/components/Count.vue | 38 ++++++++++ .../hello_vue3/src/components/LoveTalk.vue | 37 +++++++++ 学习VUE/hello_vue3/src/main.ts | 6 ++ 学习VUE/hello_vue3/src/pages/News.vue | 13 +++- 学习VUE/hello_vue3/src/router/index.ts | 4 + 学习VUE/hello_vue3/笔记/路由app写法.vue | 75 +++++++++++++++++++ 学习VUE/hello_vue3/笔记/路由重定向.ts | 42 +++++++++++ 8 files changed, 218 insertions(+), 68 deletions(-) create mode 100644 学习VUE/hello_vue3/src/components/Count.vue create mode 100644 学习VUE/hello_vue3/src/components/LoveTalk.vue create mode 100644 学习VUE/hello_vue3/笔记/路由app写法.vue create mode 100644 学习VUE/hello_vue3/笔记/路由重定向.ts diff --git a/学习VUE/hello_vue3/src/App.vue b/学习VUE/hello_vue3/src/App.vue index 78d2f0a..2131d76 100644 --- a/学习VUE/hello_vue3/src/App.vue +++ b/学习VUE/hello_vue3/src/App.vue @@ -1,75 +1,16 @@ diff --git a/学习VUE/hello_vue3/src/components/Count.vue b/学习VUE/hello_vue3/src/components/Count.vue new file mode 100644 index 0000000..3343508 --- /dev/null +++ b/学习VUE/hello_vue3/src/components/Count.vue @@ -0,0 +1,38 @@ + + + + + \ No newline at end of file diff --git a/学习VUE/hello_vue3/src/components/LoveTalk.vue b/学习VUE/hello_vue3/src/components/LoveTalk.vue new file mode 100644 index 0000000..9fa0ce6 --- /dev/null +++ b/学习VUE/hello_vue3/src/components/LoveTalk.vue @@ -0,0 +1,37 @@ + + + + + \ No newline at end of file diff --git a/学习VUE/hello_vue3/src/main.ts b/学习VUE/hello_vue3/src/main.ts index a4c897d..907e1eb 100644 --- a/学习VUE/hello_vue3/src/main.ts +++ b/学习VUE/hello_vue3/src/main.ts @@ -4,9 +4,15 @@ import { createApp } from 'vue' import App from './App.vue' // 引入路由器 import router from "./router"; +// 第一步:引入pinia +import {createPinia} from 'pinia' +// 第二步:创建pinia +const pinia = createPinia() //创建一个app const app = createApp(App) //使用路由器 app.use(router) +// 第三步:安装pinia +app.use(pinia) //挂载整个应用到app容器中 app.mount('#app') diff --git a/学习VUE/hello_vue3/src/pages/News.vue b/学习VUE/hello_vue3/src/pages/News.vue index 309c5db..f5a36ca 100644 --- a/学习VUE/hello_vue3/src/pages/News.vue +++ b/学习VUE/hello_vue3/src/pages/News.vue @@ -2,7 +2,7 @@
@@ -13,8 +13,8 @@ diff --git a/学习VUE/hello_vue3/笔记/路由重定向.ts b/学习VUE/hello_vue3/笔记/路由重定向.ts new file mode 100644 index 0000000..e6ada50 --- /dev/null +++ b/学习VUE/hello_vue3/笔记/路由重定向.ts @@ -0,0 +1,42 @@ +import {createRouter, createWebHistory} from 'vue-router' + +import Home from '@/pages/Home.vue' +import News from '@/pages/News.vue' +import About from '@/pages/About.vue' +import Details from '@/pages/Details.vue' + +//创建路由器 +const router = createRouter({ + history: createWebHistory(), //路由器的工作模式 + routes: [ + { + name: 'home', + path: '/', + component: Home + }, + { + name: 'news', + path: '/news', + component: News, + children: [ + { + name: 'news-details', + path: 'details', // 注意:子路由的 path 不需要以 "/" 开头 + component: Details + } + ] + }, + { + name: 'about', + path: '/about', + component: About + }, + { + path: '/news', + redirect: '/about', // 重定向 + } + ] +}) + +// 暴露出去 router +export default router \ No newline at end of file