vue-router -- 基本配置
2017-09-16 00:00
399 查看
基础的完整sample(戳这里)
对路由参数的变化作出响应的话,你可以简单地 watch(监测变化) $route 对象:
router.replace(location)
router.go(n)
命名路由 在routes数组配置中添加name键值对,
命名视图 同时(同级)展示多个视图时候,如sidebar header main ……,我们需要同级路由,请注意下面是components(不是component)参数
重定向 _redirect_参数在routes配置中可接受为字符串、命名对象、“to”函数,详情请戳这里
别名 _alias_更像是说假路由,URL变成了alias配置的值,但是视图还是path对应的component
mode 两种模式: _hash _和 history
对路由参数的变化作出响应的话,你可以简单地 watch(监测变化) $route 对象:
const User = { template: '...', watch: { '$route' (to, from) { // 对路由变化作出响应... } } }
编程式的vue-router操作:
router.push(location)router.replace(location)
router.go(n)
命名路由 在routes数组配置中添加name键值对,
// 参数配置 const router = new VueRouter({ routes: [ { path: '/user/:userId', name: 'user', component: User } ] }) // 链接到该路由的方法 // 1.<router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link> // 2.router.push({ name: 'user', params: { userId: 123 }})
命名视图 同时(同级)展示多个视图时候,如sidebar header main ……,我们需要同级路由,请注意下面是components(不是component)参数
// template 定义 <router-view class="view one"></router-view> <router-view class="view two" name="a"></router-view> <router-view class="view three" name="b"></router-view> // routes参数定义 const router = new VueRouter({ routes: [ { path: '/', components: { default: Foo, a: Bar, b: Baz } } ] })
重定向 _redirect_参数在routes配置中可接受为字符串、命名对象、“to”函数,详情请戳这里
别名 _alias_更像是说假路由,URL变成了alias配置的值,但是视图还是path对应的component
mode 两种模式: _hash _和 history
相关文章推荐
- nginx配置vue-router+webpack项目部署访问刷新出现404问题
- vue-cli之router基本使用方法详解
- router的安装和基本配置
- vue+webpack 组件化开发基本配置
- vue-router基本概念及使用
- vue脚手架基本使用(包括vue-router的基本使用)
- Vue项目 二、依赖安装以及基本配置
- vue-router路由的配置及用法
- Vue2.0 框架配置:vue-cli + vue-router + vuex
- CISCO router基本配置
- 使用VUE-CLI构建一个项目基本的配置
- vue学习之二:vue-router简单配置搭建单页应用
- Router的基本配置实例
- Vue-router基本使用
- Vue——axios基本配置及请求拦截
- vue-router+nginx 非根路径配置方法
- vueJs+webpack单页面应用--vue-router配置
- vue-router基本使用
- vue2.0,vue-router配置
- vuejs router history 配置到iis的方法