diff --git a/demo/component-2/src/App.vue b/demo/component-basic/src/App.vue similarity index 100% rename from demo/component-2/src/App.vue rename to demo/component-basic/src/App.vue diff --git a/demo/component-2/src/main.js b/demo/component-basic/src/main.js similarity index 100% rename from demo/component-2/src/main.js rename to demo/component-basic/src/main.js diff --git a/demo/component-1.html b/demo/component.html similarity index 100% rename from demo/component-1.html rename to demo/component.html diff --git a/demo/router-roue/App.vue b/demo/router-roue/App.vue new file mode 100644 index 0000000..0af406b --- /dev/null +++ b/demo/router-roue/App.vue @@ -0,0 +1,27 @@ + + diff --git a/demo/router-roue/main.js b/demo/router-roue/main.js new file mode 100644 index 0000000..ff25769 --- /dev/null +++ b/demo/router-roue/main.js @@ -0,0 +1,5 @@ +import {createApp} from "vue"; +import App from "./App.vue" +import router from './router' + +createApp(App).use(router).mount('#app') diff --git a/demo/router-roue/router/index.js b/demo/router-roue/router/index.js new file mode 100644 index 0000000..d26718e --- /dev/null +++ b/demo/router-roue/router/index.js @@ -0,0 +1,47 @@ +// 引入必要的router组件 +import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router' +// 引入视图 +import HomeView from '../views/HomeView.vue' + +const Header = () => import('../views/HeaderView.vue') +const Test = () => import('../views/TestView.vue') + +// 创建路由,包含path,name,component属性, component属性可以使用箭头函数直接引入视图 +const routes = [ + { + path: '/', + name: 'home', + component: HomeView + }, + { + path: '/about', + name: 'about', + component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue') + }, + // 配合params参数的路由path改造 + { + path: '/about/:id/:name', + name: 'about-params', + component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue') + }, + { + path: '/header', + name: 'header', + component: Header, + }, + { + path: '/test', + name: 'test', + component: Test, + } +] + +// 创建路由器,使用createRouter方法,传入history(路由类型)和 创建好的路由routes +// 路由类型分为hash型和html5型,分别为createWebHashHistory和createWebHistory +const router = createRouter({ + history: createWebHistory(), + routes +}) + +// 导出路由 +export default router diff --git a/demo/router-roue/views/AboutView.vue b/demo/router-roue/views/AboutView.vue new file mode 100644 index 0000000..89057b2 --- /dev/null +++ b/demo/router-roue/views/AboutView.vue @@ -0,0 +1,12 @@ + + + diff --git a/demo/router-roue/views/HeaderView.vue b/demo/router-roue/views/HeaderView.vue new file mode 100644 index 0000000..a4e983c --- /dev/null +++ b/demo/router-roue/views/HeaderView.vue @@ -0,0 +1,18 @@ + + + diff --git a/demo/router-roue/views/HomeView.vue b/demo/router-roue/views/HomeView.vue new file mode 100644 index 0000000..8af0b4b --- /dev/null +++ b/demo/router-roue/views/HomeView.vue @@ -0,0 +1,3 @@ + diff --git a/demo/router-roue/views/TestView.vue b/demo/router-roue/views/TestView.vue new file mode 100644 index 0000000..f31e9a5 --- /dev/null +++ b/demo/router-roue/views/TestView.vue @@ -0,0 +1,43 @@ + + + + + + diff --git a/src/App.vue b/src/App.vue index ff1c1f3..0af406b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,7 +1,27 @@ + diff --git a/src/router/index.js b/src/router/index.js index 8b8716a..d26718e 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,27 +1,46 @@ // 引入必要的router组件 -import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router' +import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router' // 引入视图 import HomeView from '../views/HomeView.vue' +const Header = () => import('../views/HeaderView.vue') +const Test = () => import('../views/TestView.vue') + // 创建路由,包含path,name,component属性, component属性可以使用箭头函数直接引入视图 const routes = [ - { - path: '/', - name: 'home', - component: HomeView - }, - { - path: '/about', - name: 'about', - component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue') - } + { + path: '/', + name: 'home', + component: HomeView + }, + { + path: '/about', + name: 'about', + component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue') + }, + // 配合params参数的路由path改造 + { + path: '/about/:id/:name', + name: 'about-params', + component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue') + }, + { + path: '/header', + name: 'header', + component: Header, + }, + { + path: '/test', + name: 'test', + component: Test, + } ] // 创建路由器,使用createRouter方法,传入history(路由类型)和 创建好的路由routes // 路由类型分为hash型和html5型,分别为createWebHashHistory和createWebHistory const router = createRouter({ - history: createWebHistory(), - routes + history: createWebHistory(), + routes }) // 导出路由 diff --git a/src/views/AboutView.vue b/src/views/AboutView.vue index 56b5bc9..89057b2 100644 --- a/src/views/AboutView.vue +++ b/src/views/AboutView.vue @@ -1,3 +1,12 @@ + + diff --git a/src/views/HeaderView.vue b/src/views/HeaderView.vue new file mode 100644 index 0000000..a4e983c --- /dev/null +++ b/src/views/HeaderView.vue @@ -0,0 +1,18 @@ + + + diff --git a/src/views/TestView.vue b/src/views/TestView.vue new file mode 100644 index 0000000..f31e9a5 --- /dev/null +++ b/src/views/TestView.vue @@ -0,0 +1,43 @@ + + + + + +