


[Compilation and sharing] Some vue-router related interview questions (with answer analysis)
This article will summarize and share with you some vue-router related interview questions (with answer analysis), help you sort out the basic knowledge, and enhance the vue-router knowledge reserve. It is worth collecting, come and take a look!
The principle of vue-router
In a single-page application, switching between different components needs to be implemented through front-end routing .
Front-end routing
1.key is the path, value is the component, used to display the page content
2. Working process: when the browser's path changes , the corresponding component will be displayed. vue-router
’s routing function: Map components to routes and then render them
Mainly
How to change the URL without causing the page to refresh
How to detect the URL change [Related recommendations: vuejs video tutorial, web front-end development 】
The hash pattern of the route
hash is the
## in the URL ## and the following part, the URL after
# will not be sent to the server,
so changing the hash part in the URL will not cause the page to refresh- Window can monitor
onhashchange
event changes. When the hash changes, read the content after
#, match routing rules based on the information, and change the page routing by changing
window.location.hash.
Three ways to change the URL
- Change the URL through the browser forward and backward
- Change the URL through tags
- Change the URL through window.location
Advantages
- Only the front-end needs to configure the routing table, no back-end participation is required
- Good compatibility, all browsers can support it
- Changes in the hash value will not send requests to the backend, it is completely front-end routing
The hash value needs to be preceded by #, which does not comply with the url specification and is not beautiful
routing history mode - using the new pushState() and replaceState()## in the history interface of H5's history API
-
The#html5 # Method, used to add and modify records in the browsing history, change the page path,
so that the URL jump will not reload the page.
popstate - event is similar to the
hashchange
event, but the popstate event is somewhat different:
Only when making thebrowser popState will be called only when behavior
is triggered. It will be triggered when the user clicks the browser's back button and forward button, or uses JavaScript to call the History.back(), History.forward(), and History.go() methods. Advantages
Conforms to URL address specifications, no # is required, and it is more beautiful to use
- Disadvantages
When the user
manually enters the address or refreshes the page, a url request- will be initiated, and the backend needs to configure the index.html page The user cannot match the static resource, otherwise a 404 error will occur.
- The compatibility is relatively poor, and the new pushState() and
- replaceState( are used in the HTML5 History object. )
method requires the support of a specific browser.
What is the difference between $route and $router? $router is an instance object of VueRouter, representing the only router object for the entire application. Contains routing jump methods, hook functions, etc. $route is the current routing object, which represents the routing rules of this component. Each route will have a route object, which is a local object.
Vue-router parameters are passed in several ways, what are the differences?
How to specify the jump route | If no parameters are passed | Can parameters be passed without the required value | ||
---|---|---|---|---|
Path/params parameter | You must use name to specify the route | params is part of the route , If placeholders are configured, If this route has params parameters, but this parameter is not passed during the jump, the jump will fail or the page will have no content. |
Placeholders that are not included in the delivery path will not be displayed on the address bar and will be lost upon refresh |
query parameters |
Path? key1=val1 & key2=val2.... |
1. You can use name to specify the route 2. You can use path to specify the route |
query It is a parameter spliced after the url. It doesn’t matter if it is not available. | query will not
The above is the detailed content of [Compilation and sharing] Some vue-router related interview questions (with answer analysis). For more information, please follow other related articles on the PHP Chinese website!

Vue.js and React each have their own advantages in scalability and maintainability. 1) Vue.js is easy to use and is suitable for small projects. The Composition API improves the maintainability of large projects. 2) React is suitable for large and complex projects, with Hooks and virtual DOM improving performance and maintainability, but the learning curve is steeper.

The future trends and forecasts of Vue.js and React are: 1) Vue.js will be widely used in enterprise-level applications and have made breakthroughs in server-side rendering and static site generation; 2) React will innovate in server components and data acquisition, and further optimize the concurrency model.

Netflix's front-end technology stack is mainly based on React and Redux. 1.React is used to build high-performance single-page applications, and improves code reusability and maintenance through component development. 2. Redux is used for state management to ensure that state changes are predictable and traceable. 3. The toolchain includes Webpack, Babel, Jest and Enzyme to ensure code quality and performance. 4. Performance optimization is achieved through code segmentation, lazy loading and server-side rendering to improve user experience.

Vue.js is a progressive framework suitable for building highly interactive user interfaces. Its core functions include responsive systems, component development and routing management. 1) The responsive system realizes data monitoring through Object.defineProperty or Proxy, and automatically updates the interface. 2) Component development allows the interface to be split into reusable modules. 3) VueRouter supports single-page applications to improve user experience.

The main disadvantages of Vue.js include: 1. The ecosystem is relatively new, and third-party libraries and tools are not as rich as other frameworks; 2. The learning curve becomes steep in complex functions; 3. Community support and resources are not as extensive as React and Angular; 4. Performance problems may be encountered in large applications; 5. Version upgrades and compatibility challenges are greater.

Netflix uses React as its front-end framework. 1.React's component development and virtual DOM mechanism improve performance and development efficiency. 2. Use Webpack and Babel to optimize code construction and deployment. 3. Use code segmentation, server-side rendering and caching strategies for performance optimization.

Reasons for Vue.js' popularity include simplicity and easy learning, flexibility and high performance. 1) Its progressive framework design is suitable for beginners to learn step by step. 2) Component-based development improves code maintainability and team collaboration efficiency. 3) Responsive systems and virtual DOM improve rendering performance.

Vue.js is easier to use and has a smooth learning curve, which is suitable for beginners; React has a steeper learning curve, but has strong flexibility, which is suitable for experienced developers. 1.Vue.js is easy to get started with through simple data binding and progressive design. 2.React requires understanding of virtual DOM and JSX, but provides higher flexibility and performance advantages.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
