web123456

Vue2.0—Related Interview Questions

1. Is active-class the property of which component? How to define nested routes?

Answer: The router-link component of the vue-router module.

2. How to define the dynamic routing of vue-router? How to get the dynamic parameters passed?

Answer: In the file in the router directory, add: /d to the path attribute to use the router object

3. What are the types of navigation hooks for vue-router?

Answer: 3 types

The first type, global hook(to,from,next) Make judgment and intercept before the function jumps

beforeEach
beforeResolve
afterEach

  1. //Define a route
  2. const router = new VueRouter({ ... })
  3. // Call before clicking
  4. ((to, from, next) => {
  5. // ...
  6. })
  7. //Click navigation and call
  8. (route => {
  9. // ...
  10. })

The second type: hooks in the component

beforeRouteEnter
beforeRouteUpdate (2.2 added)
beforeRouteLeave

  1. let fromPath = '';
  2. export default{
  3. beforeRouteEnter (to, from, next) {
  4. // Called before rendering the corresponding route of the component is confirmed
  5. // No! able! Get component instance `this`
  6. // Because the component instance has not been created before the hook is executed
  7. fromPath = ;
  8. next();
  9. },
  10. }

The third type: individual routing and exclusive components

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. What is scss? What are the steps to install? What are the major characteristics?

Answer: Preprocess the css, and current the cssfunctionWrite, define variables, nest;

Install css-loader first,node-loader, sass-loader and other loader modules,

existwebpack- Add an additional extension to the configuration file: extension,

Add another module: test and loader in module

5. What is scss? What are the installation steps in? What are the major characteristics?

  1. Answer: Precompilation of css.
  2. Steps to use:
  3. Step 1: Use npm to lower three loaders (sass-loader, css-loader, node-sass)
  4. Step 2: Find it in the build directory and add an extension.scss to the extends property
  5. Step 3: Configure a module property in the same file
  6. Step 4: Then add the lang attribute to the component's style tag, for example: lang=”scss”
  7. What are the major characteristics:
  8. 1, variables can be used, for example ($ variable name=value);
  9. 2, you can use a mixer, for example ()
  10. 3, can be nested