1.vue-router 怎么重定向页面?

  • 路由中配置 redirect 属性
  • 使用路由的别名来完成重定向

2.vue-router 怎么配置 404 页面?

path: '*',放在最后一个

3.切换路由时,需要保存草稿的功能,怎么实现呢?

  • beforeDe
  • beforeRouteLeave

4.vue-router 路由有几种模式?说说它们的区别?

hash 模式的特点

hash 表示的是地址栏 URL 中#符号(也称作为锚点), hash 虽然会出现在 URL 中, 但是不会被包含在 Http 请求中, 因此 hash 值改变不会重新加载页面.由于 hash 值变化不会引起浏览器向服务器发出请求, 而且 hash 改变会触发 hashchange 事件, 浏览器的进后退也能对其进行控制, 所以在 HTML5 之前, 基本都是使用 hash 来实现前端路由.

history 模式的特点

利用了 HTML5 新增的 pushState()和 replaceState()两个 api, 通过这两个 api 完成 URL 跳转不会重新加载页面.同时 history 模式解决了 hash 模式存在的问题. hash 的传参是基于 URL 的, 如果要传递复杂的数据, 会有体积限制,

5.说说你对 router-link 的了解

vue-router 插件的其中一个组件, 用于跳转路由, 类似于 a 标签, 它一般也会渲染成 a 标签, 但是可以通过 tag 来变更默认渲染元素, 通过 to 来跳转

6.切换到新路由时,页面要滚动到顶部或保持原先的滚动位置怎么做呢?

滚动到顶部:在 new Router()的时候,配置

scrollBehavior(to, from, savedPosition) {
return { x: 0, y: 0 }
}

7.如何获取路由传过来的参数?

如果使用 query 方式传入的参数使用 this.$route.query 接收

如果使用params方式传入的参数使用this.$router.params 接收

8.说说 active-class 是哪个组件的属性?

active-class 是 vue-router 模块的 router-link 组件中的属性,用来做选中样式的切换;

9.在 vue 组件中怎么获取到当前的路由信息?

this.$route.path / this.$route

10.怎样动态加载路由?

router.addRoutes

11.怎么实现路由懒加载呢?

import 异步加载const component = () =>import('./....')

12.说说 vue-router 完整的导航解析流程是什么?

  1. 导航被触发;
  2. 在失活的组件里调用 beforeRouteLeave 守卫;
  3. 调用全局 beforeEach 守卫;
  4. 在复用组件里调用 beforeRouteUpdate 守卫;
  5. 调用路由配置里的 beforeEnter 守卫;
  6. 解析异步路由组件;
  7. 在被激活的组件里调用 beforeRouteEnter 守卫;
  8. 调用全局 beforeResolve 守卫;
  9. 导航被确认;
  10. 调用全局的 afterEach 钩子;
  11. DOM 更新;
  12. 用创建好的实例调用 beforeRouteEnter 守卫中传给 next 的回调函数。

13.route 和 router 有什么区别?

route 代表当前路由对象,router 代表整个 vue 实例下的路由对象

14.vue-router 钩子函数有哪些?都有哪些参数?

beforeEach,afterEach

beforeEach 主要有三个参数,to,form,next

[Vue] vue-router-interview的更多相关文章

  1. 三、vue之router

    三.vue之router 此时vue的脚手架.创建项目已经完成. ... vue的运行流程 index.html-->main.js-->App.vue-->router/index ...

  2. Vue中router两种传参方式

    Vue中router两种传参方式 1.Vue中router使用query传参 相关Html: <!DOCTYPE html> <html lang="en"> ...

  3. 四 Vue学习 router学习

    index.js: 按需加载组件: const login = r => require.ensure([], () => r(require('@/page/login')), 'log ...

  4. vue 中router.go;router.push和router.replace的区别

    vue 中router.go:router.push和router.replace的区别:https://blog.csdn.net/div_ma/article/details/79467165 t ...

  5. 【vue】 router.beforeEach

    import store from '@/store' const Vue = require('vue') const Router = require('vue-router') Vue.use( ...

  6. vue & this.$router.resolve

    vue & this.$router.resolve gotoAutoUpdate (query = {}) { const { href } = this.$router.resolve({ ...

  7. vue & vue router & dynamic router

    vue & vue router & dynamic router https://router.vuejs.org/guide/essentials/dynamic-matching ...

  8. vue & vue router & match bug

    vue & vue router & match bug match bugs solution name must be router https://stackoverflow.c ...

  9. Vue中router路由的使用、router-link的使用(在项目中的实际运用方式)

    文章目录 1.先看router中的index.js文件 2.router-link的使用 3.实现的效果 前提:router已经安装 1.先看router中的index.js文件 import Vue ...

  10. Vue Vue.use() / Vue.component / router-view

    Vue.use Vue.use 的作用是安装插件 Vue.use 接收一个参数 如果这个参数是函数的话,Vue.use 直接调用这个函数注册组件 如果这个参数是对象的话,Vue.use 将调用 ins ...

随机推荐

  1. HDU 4725 The Shortest Path in Nya Graph (最短路 )

    This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just ...

  2. [python 笔记] __iter__迭代器

    可迭代对象和迭代器 https://blog.csdn.net/nightcharm/article/details/78964676 可迭代对象 对象里面含有__iter__()方法的实现,对象的_ ...

  3. Unity3D_(游戏)卡牌03_选关界面

      启动屏界面.主菜单界面.选关界面.游戏界面 卡牌01_启动屏界面 传送门 卡牌02_主菜单界面 传送门 卡牌03_选关界面 传送门 卡牌04_游戏界面    传送门 选关界面效果 (鼠标放在不同关 ...

  4. python学习之路(3)

    字符串和编码 因为python最早只支持ASCII编码普通的字符串'ABC'在Python内部都是ASCII编码的.Python提供了ord()和chr()函数,可以把字母和对应的数字相互转换 后来p ...

  5. C++入门经典-例6.15-通过字符串函数连接两个字符数组

    1:代码如下 // 6.15.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...

  6. python学习---50行代码实现图片转字符画2

    from PIL import Image codeLib = '''@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<> ...

  7. centos 系统时间设置

    在我们使用CentOS系统的时候,也许时区经常会出现问题,有时候改完之后还是会出错,下面我们就来学习一种方法来改变这个状况.如果没有安装,而你使用的是 CentOS系统 那使用命令 yum insta ...

  8. Java JDBC 基础

    JDBC API 包含以下几个核心部分: 1:JDBC 驱动 2:Connections (连接) 3:Statements (声明) 4:Result Sets (结果集) JDBC: 打开数据库连 ...

  9. shell脚本获取绝对路径

    当前脚本全路径 echo $(readlink -f "$0") 获取绝对路径(不带文件名) echo $(dirname $(readlink -f "$0" ...

  10. https的那些坑

    1.时间 一些老手机不是系统自动对时,时间错误会报错. com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeExceptio ...