富贵资源网 Design By www.hznty.com

vue路由插件,vuer Router,使vue官方的路由管理其,和vue高度耦合

  1.vue-Router的使用  

import Vue from 'vue'
import Router from 'vue-router' //引入路由组件

Vue.use(Router)

new Router({
  mode: 'history', //路由的两种模式 hash 和history 默认使history模式
  routes: [
  {
   path: '/',
   name: 'home',
   component: () => import(xxx.vue)
  },
  {
   path: '/about',
   name: 'about',
   component: () => import()
  }
 ]
})

  2.路由的跳转

    this.$router.push('/path')

    this.$router.push({name:'routername'})

    路由的get方式传值

    this.$router.push({name:'routername',query:{id:xxx}})

    路由的post方式传值

    this.$router.push({name:'routername',params:{id:xxx}})

  3.路由的后退

    this.$router.go(-1) 

    this.$router.back()

  4.路由的前进

    this.$router.forward() 

  5.替换当前路由,在路由历史中不会再出现该路由

    this.$router.replace(location)

  6.当前路由的对象属性(一定要记得是小写的$route,并且没有r)

     this.$route.path   当前路由路径 path

     this.$route.name  当前路由名称

     this.$route.params.id  post方式传参时,获取id的值

     this.$route.query.id get方式传参时获取id的值

    this.$route.hash 当前路由的hash值,带#

   7.linkActiveClass

    当前激活的路由的class类名,默认是"router-link-active"

  8.scrollBehavior 

    切换路由时页面滚动到具体位子

  9.router-link 中的tag标签,生成具体的标签的html 元素

  10.router-view 路由组件具体渲染的地方

  11.全部的路由钩子函数(导航首位)

    11.1router.beforeEach  全局前置首位

    11.2router.beforeResolve 全局解析守卫

    11.3router.afterEach 全局后置守卫

    11.4beforeEnter 路由独享守卫

    组件内守卫

    11.5beforerouteEnter 进入

    11.6beforerouteUpdate  更新

    11.7beforerouteLeave 离开

/* 全局前置守卫 */
router.beforeEach(function (to, from, next) {
 // to 将要进路的路由 route
 // from 离开的路由 route
 // next 进入下一个路由,不调用则不会进入下一个路由
 console.log('全局前置守卫')
 next()
})

/* 全局解析守卫 */
router.beforeResolve((to, from, next) => {
 // to 将要进路的路由 route
 // from 离开的路由 route
 console.log('全局解析守卫')
 next()
})

/* 全局后置守卫 */
router.afterEach((to, from) => {
 // to 将要进路的路由 route
 // from 离开的路由 route
 console.log('全局后置守卫')
})
/* 组件独享守卫 */
   beforeEnter(to, from, next) {
    console.log('组件内独享守卫')
    next()
   }
 beforeRouteEnter(to, from, next) {
  console.log('组件内守卫进入')
  next()
 },
 beforeRouteUpdate(to, from, next) {
  console.log('组件内守卫更新')
  next()
 },
 beforeRouteLeave(to, from, next) {
  console.log('组件内守卫离开前')
  next()
 }

  执行顺序,

    1.前组件内守卫离开

    2.全局前置守卫

    3.路由独享守卫

    4.组件内守卫进入

    5.全局解析守卫

    6.全局后置守卫

  或者时刷新组件时(/about 跳转到/about"color: #ff0000">总结

以上所述是小编给大家介绍的vue路由vue-route的实例代码,非常不错,具有一定的参考借鉴价值,需要的朋友参考下吧!

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。