diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/App.vue b/20_脚手架/vue_code/34.src_编程式路由导航/App.vue new file mode 100644 index 0000000..14872a9 --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/App.vue @@ -0,0 +1,34 @@ + + + diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/assets/logo.png b/20_脚手架/vue_code/34.src_编程式路由导航/assets/logo.png new file mode 100644 index 0000000..f3d2503 Binary files /dev/null and b/20_脚手架/vue_code/34.src_编程式路由导航/assets/logo.png differ diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/components/Banner.vue b/20_脚手架/vue_code/34.src_编程式路由导航/components/Banner.vue new file mode 100644 index 0000000..ab3725d --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/components/Banner.vue @@ -0,0 +1,23 @@ + + + diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/main.js b/20_脚手架/vue_code/34.src_编程式路由导航/main.js new file mode 100644 index 0000000..9c406ac --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/main.js @@ -0,0 +1,23 @@ +// 引入Vue +import Vue from "vue"; +// 引入App +import App from "./App"; +// 引入VueRouter +import VueRouter from "vue-router"; +// 引入router +import router from "@/router"; + +// 设置Vue +Vue.config.productionTip = false + +// 使用插件 +Vue.use(VueRouter) + +// 实例化Vue +new Vue({ + components: { + App + }, + render: h => h(App), + router: router, +}).$mount('#app') diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/pages/About.vue b/20_脚手架/vue_code/34.src_编程式路由导航/pages/About.vue new file mode 100644 index 0000000..26560f1 --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/pages/About.vue @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/pages/Detail.vue b/20_脚手架/vue_code/34.src_编程式路由导航/pages/Detail.vue new file mode 100644 index 0000000..95ef4fa --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/pages/Detail.vue @@ -0,0 +1,17 @@ + + + diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/pages/Home.vue b/20_脚手架/vue_code/34.src_编程式路由导航/pages/Home.vue new file mode 100644 index 0000000..f40e1c1 --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/pages/Home.vue @@ -0,0 +1,36 @@ + + + + + \ No newline at end of file diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/pages/Message.vue b/20_脚手架/vue_code/34.src_编程式路由导航/pages/Message.vue new file mode 100644 index 0000000..746f387 --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/pages/Message.vue @@ -0,0 +1,68 @@ + + + diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/pages/News.vue b/20_脚手架/vue_code/34.src_编程式路由导航/pages/News.vue new file mode 100644 index 0000000..a8d4f7b --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/pages/News.vue @@ -0,0 +1,15 @@ + + + diff --git a/20_脚手架/vue_code/34.src_编程式路由导航/router/index.js b/20_脚手架/vue_code/34.src_编程式路由导航/router/index.js new file mode 100644 index 0000000..b5c9337 --- /dev/null +++ b/20_脚手架/vue_code/34.src_编程式路由导航/router/index.js @@ -0,0 +1,55 @@ +import VueRouter from "vue-router"; + +// 引入组件 +import About from "@/pages/About.vue" +import Home from "@/pages/Home.vue" +import News from "@/pages/News.vue" +import Message from "@/pages/Message.vue"; +import Detail from "@/pages/Detail.vue"; + +// 创建一个路由器 +export default new VueRouter({ + routes: [ + { + name: 'guanyu', + path: '/about', + component: About + }, + { + path: '/home', + component: Home, + children: [ + { + path: 'news', + component: News, + }, + { + path: 'message', + component: Message, + children: [ + { + name: 'xiangqing', + path: 'detail/:id/:title', + component: Detail, + // props的第一种写法,key-val格式,通过props的方式传给detail组件 + // props: {a:1,b:'hello'} + // props的第二种写法,布尔值,若布尔值为真,就会把路由组件收到的params参数以props的形式传给detail + // props: true + // props的第三种写法,函数形式 + props($route) { + return { + id: $route.query.id, + title: $route.query.title + } + } + // 解构赋值的写法 + // props({query:{id,title}}) { + // return {id, title} + // } + } + ] + } + ] + }, + ] +}) diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/App.vue b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/App.vue new file mode 100644 index 0000000..14872a9 --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/App.vue @@ -0,0 +1,34 @@ + + + diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/assets/logo.png b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/assets/logo.png new file mode 100644 index 0000000..f3d2503 Binary files /dev/null and b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/assets/logo.png differ diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/components/Banner.vue b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/components/Banner.vue new file mode 100644 index 0000000..ab3725d --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/components/Banner.vue @@ -0,0 +1,23 @@ + + + diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/main.js b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/main.js new file mode 100644 index 0000000..9c406ac --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/main.js @@ -0,0 +1,23 @@ +// 引入Vue +import Vue from "vue"; +// 引入App +import App from "./App"; +// 引入VueRouter +import VueRouter from "vue-router"; +// 引入router +import router from "@/router"; + +// 设置Vue +Vue.config.productionTip = false + +// 使用插件 +Vue.use(VueRouter) + +// 实例化Vue +new Vue({ + components: { + App + }, + render: h => h(App), + router: router, +}).$mount('#app') diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/About.vue b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/About.vue new file mode 100644 index 0000000..26560f1 --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/About.vue @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Detail.vue b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Detail.vue new file mode 100644 index 0000000..95ef4fa --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Detail.vue @@ -0,0 +1,17 @@ + + + diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Home.vue b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Home.vue new file mode 100644 index 0000000..9436f2f --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Home.vue @@ -0,0 +1,40 @@ + + + + + \ No newline at end of file diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Message.vue b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Message.vue new file mode 100644 index 0000000..746f387 --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/Message.vue @@ -0,0 +1,68 @@ + + + diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/News.vue b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/News.vue new file mode 100644 index 0000000..e6e997a --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/pages/News.vue @@ -0,0 +1,32 @@ + + + diff --git a/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/router/index.js b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/router/index.js new file mode 100644 index 0000000..b5c9337 --- /dev/null +++ b/20_脚手架/vue_code/35_src_路由的缓存和路由的两个生命周期钩子/router/index.js @@ -0,0 +1,55 @@ +import VueRouter from "vue-router"; + +// 引入组件 +import About from "@/pages/About.vue" +import Home from "@/pages/Home.vue" +import News from "@/pages/News.vue" +import Message from "@/pages/Message.vue"; +import Detail from "@/pages/Detail.vue"; + +// 创建一个路由器 +export default new VueRouter({ + routes: [ + { + name: 'guanyu', + path: '/about', + component: About + }, + { + path: '/home', + component: Home, + children: [ + { + path: 'news', + component: News, + }, + { + path: 'message', + component: Message, + children: [ + { + name: 'xiangqing', + path: 'detail/:id/:title', + component: Detail, + // props的第一种写法,key-val格式,通过props的方式传给detail组件 + // props: {a:1,b:'hello'} + // props的第二种写法,布尔值,若布尔值为真,就会把路由组件收到的params参数以props的形式传给detail + // props: true + // props的第三种写法,函数形式 + props($route) { + return { + id: $route.query.id, + title: $route.query.title + } + } + // 解构赋值的写法 + // props({query:{id,title}}) { + // return {id, title} + // } + } + ] + } + ] + }, + ] +}) diff --git a/20_脚手架/vue_code/src/App.vue b/20_脚手架/vue_code/src/App.vue index b91ac90..14872a9 100644 --- a/20_脚手架/vue_code/src/App.vue +++ b/20_脚手架/vue_code/src/App.vue @@ -6,11 +6,11 @@
- - About - Home - - + + About + Home + +
@@ -26,6 +26,7 @@ diff --git a/20_脚手架/vue_code/src/pages/Home.vue b/20_脚手架/vue_code/src/pages/Home.vue index f40e1c1..9436f2f 100644 --- a/20_脚手架/vue_code/src/pages/Home.vue +++ b/20_脚手架/vue_code/src/pages/Home.vue @@ -11,7 +11,11 @@
diff --git a/20_脚手架/vue_code/src/pages/Message.vue b/20_脚手架/vue_code/src/pages/Message.vue index 0e383a3..746f387 100644 --- a/20_脚手架/vue_code/src/pages/Message.vue +++ b/20_脚手架/vue_code/src/pages/Message.vue @@ -15,6 +15,8 @@ }"> {{ m.title }} + +
@@ -40,6 +42,27 @@ export default { {id: '003', title: '消息003'} ] } + }, + methods:{ + pushShow(m) { + // console.log(this.$router) + this.$router.push({ + name: 'xiangqing', + query: { + id: m.id, + title: m.title, + } + }) + }, + replaceShow(m) { + this.$router.replace({ + name: 'xiangqing', + query: { + id: m.id, + title: m.title, + } + }) + } } } diff --git a/20_脚手架/vue_code/src/pages/News.vue b/20_脚手架/vue_code/src/pages/News.vue index a8d4f7b..e6e997a 100644 --- a/20_脚手架/vue_code/src/pages/News.vue +++ b/20_脚手架/vue_code/src/pages/News.vue @@ -1,15 +1,32 @@