Vue Router
vue-router是什么~~vue-router是Vue的路由系统,定位资源的,我们可以不进行整页刷新去切换页面内容。 vue-router的安装和基本配置vue-router.js 可以下载 也可以用cdn,基本配置信息看如下代码~~~ <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"> <span style="color: #0000ff;">var router = <span style="color: #0000ff;">new<span style="color: #000000;"> VueRouter({ <span style="color: #0000ff;">var app = <span style="color: #0000ff;">new<span style="color: #000000;"> Vue({ 路由的一些方法路由传参以及获取参数~~ 关于我们我是:{{$route.params.name}}我年龄是:{{$route.query.age}}routes: routes,}); <span style="color: #0000ff;">var app = <span style="color: #0000ff;">new<span style="color: #000000;"> Vue({ el: '#app'<span style="color: #000000;">,}); 命名路由~ ?注意router-link里to一定要v-bind~~ 这是主页` "/about""about"关于我们` "/user/:name"我是{{$route.params.name}}我的年龄是{{$route.query.age}}let router </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> VueRouter({
routes: routes,mode: </span>"history"<span style="color: #000000;">
});
const app </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> Vue({
el: </span>"#app"<span style="color: #000000;">,mounted(){
console.log(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">.$route)
console.log(</span><span style="color: #0000ff;">this</span><span style="color: #000000;">.$router)
}
})</span></pre>
子路由~~ 以展示详细为例~~
"/user/:name"
我是:{{$route.params.name}}我年龄是:{{$route.query.age}}`, },</span></pre>
?手动访问路由,以及传参~~ 命名路由视图 router-view 当我们只有一个 如果是content 和 footer 就需要同时显示并且不同区域~这就需要对视图进行命名~
首页关于我们错误路由的重定向~~ let routes ="**""/"
$route以及$router的区别~~ -- $route为当前router调转对象,里面可以获取name,path,query,params等~ -- $router为VueRouter实例,有$router.push方法等~~ 路由的钩子路由的生命周期就是从一个路由跳转到另一路由整个过程,下面介绍两个钩子~ router.beforeEach()? ?router.afterEach()? 详情请看代码~~ 首页""/login""登录""/user""用户管理" router = router.beforeEach(<span style="color: #0000ff;">function<span style="color: #000000;"> (to,from,next) {<span style="color: #008000;">//<span style="color: #008000;"> console.log(to) <span style="color: #008000;">//<span style="color: #008000;"> console.log(from) <span style="color: #008000;">//<span style="color: #008000;"> console.log(next) <span style="color: #008000;">//<span style="color: #008000;"> next(false) <span style="color: #0000ff;">if(to.path=="/user"<span style="color: #000000;">){ next("/login"<span style="color: #000000;">) } <span style="color: #0000ff;">else<span style="color: #000000;"> { next(); } }); router.afterEach(<span style="color: #0000ff;">function<span style="color: #000000;"> (to,from) { console.log(to) console.log(from) }); <span style="color: #0000ff;">var app = <span style="color: #0000ff;">new<span style="color: #000000;"> Vue({ next:"/"
上面的例子~~如果/user下面还有子路由的情况下会怎么样呢~????
router.beforeEach(
(to.matched.some( item.path == "/post""/login"
"/user"
用户管理VIP' router.beforeEach( "/login"(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- There is no Action mapped for namespace [/] and action
- ruby-on-rails-3 – 在SQLite3中备份/恢复数据库的简单方法
- 16.6 Swift可选链不会增加可选类型的可选性
- 手游代理人需要哪些能力?番茄孵化器告诉你
- 内存管理 – 当cocos2d-x 3.2中的Replacescene时内存不释放
- Oracle数据库合并行记录,WMSYS.WM_CONCAT 函數的用法
- 正则表达式 – 使用经典的asp进行正则表达式
- 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含
- c# – MS Word Office Automation – 填写文本表单域和复选
- malloc在一个循环中,都是连续分配的块?