Vue2.0—相关面试题

时间:2025-04-08 07:29:06

1、active-class是那个组件的属性?嵌套路由怎么定义?

答:vue-router模块的router-link组件。

2、怎么定义vue-router的动态路由?怎么获取传过来的动态参数?

答:在router目录下的文件中,对path属性加上:/d  使用router对象的

3、vue-router有哪几种导航钩子?

答:3种

 第1种、全局钩子 (to,from,next) 作用跳转前进行判断拦截

beforeEach
beforeResolve
afterEach

  1. //定义一个路由
  2. const router = new VueRouter({ ... })
  3. // 点击导航前调用
  4. ((to, from, next) => {
  5. // ...
  6. })
  7. // 点击导航后调用
  8. (route => {
  9. // ...
  10. })

第二种:组件内的钩子 

beforeRouteEnter
beforeRouteUpdate (2.2 新增)
beforeRouteLeave

  1. let fromPath = '';
  2. export default{
  3. beforeRouteEnter (to, from, next) {
  4. // 在渲染该组件的对应路由被 confirm 前调用
  5. // 不!能!获取组件实例 `this`
  6. // 因为当钩子执行前,组件实例还没被创建
  7. fromPath = ;
  8. next();
  9. },
  10. }

第三种:单独路由独享组件

beforeEnter

  1. const router = new VueRouter({
  2. routes: [
  3. {
  4. path: '/foo',
  5. component: Foo,
  6. beforeEnter: (to, from, next) => {
  7. // ...
  8. },
  9. beforeEnter: (route) => {
  10. // ...
  11. }
  12. }
  13. ]
  14. });
4、scss是什么?安装使用的步骤是?有哪几大特性?

答:预处理css、把css当前函数编写,定义变量、嵌套;

先装css-loader、node-loader、sass-loader等加载器模块,

webpack-配置文件中加多一个拓展:extenstion,

再加多一个模块:module里面test、loader

5、scss是什么?中的安装使用步骤是?有哪几大特性?

  1. 答:css的预编译。
  2. 使用步骤:
  3. 第一步:用npm 下三个loader(sass-loader、css-loader、node-sass)
  4. 第二步:在build目录找到,在那个extends属性中加一个拓展.scss
  5. 第三步:还是在同一个文件,配置一个module属性
  6. 第四步:然后在组件的style标签加上lang属性 ,例如:lang=”scss”
  7. 有哪几大特性:
  8. 1、可以用变量,例如($变量名称=值);
  9. 2、可以用混合器,例如()
  10. 3、可以嵌套