vue-router

一、 vue-router页面实现

  1. router-link点击实现组件切换;
  2. router-view组件显示的地方。

二、vue-router的js配置

  1. 定义路由配置 const routes =[ { path: '/', redirect: home }, {path: 'home', compnent: 'home'}]
  2. 定义路由 const router = new VueRouter(routes: routes)
  3. 将router注入到const app = new Vue({ router })

三、动态路由

  1. path:'/home/:id',可以通过this.$route.params获取。
  2. 注意在路由动态切换时,组件的生命周期不起作用。

watch: {

  $route (to, from) {}

}

  3.路由传参,配置query

 

四、路由原理

  1. #。后面 hash 值的变化,并不会导致浏览器向服务器发出请求;
  2. hashhistory
posted @ 2018-10-27 16:38  胖糖糖爱吃肉  阅读(150)  评论(0编辑  收藏  举报