Solve the problem of multiple Vue routes sharing one page
Below I will share with you an article that solves the problem of multiple Vue routes sharing one page. It has a good reference value and I hope it will be helpful to everyone.
In daily vue development, we may encounter the need for multiple routes to share a page, especially when routes are added dynamically. Different routes display only different data and nothing else changes. For example:
let routes = [ {path:"/zhanshan", components:Person, }, {path:"/lisi", components:Person, }, {path:"/wangwu", components:Person, } ]
In this case, we found that our page will not load again after it is loaded successfully for the first time. Therefore, the page always displays the data loaded for the first time, which gives people the impression that the routing has not taken effect. However, by observing the changes in the browser address bar, we can confirm that this has nothing to do with routing. This is very useful for students who have just started using Vue. It may cause a little trouble. In fact, this is related to the life cycle of the page. The reason why this happens is because most of its hook functions (mounted, computed...) will not start again after the page is loaded, so As a result, the page feels like there is no jump.
This kind of business requirement is actually easier to handle. In fact, we don’t need to switch pages. We only need the data in the page to change. We can monitor the change of the routing address in the page. When the address When it changes, we reload the data.
watch:{ "$route":function(to,from){ //from 对象中包含当前地址 //to 对象中包含目标地址 //其实还有一个next参数的,这个参数是控制路由是否跳转的,如果没写,可以不用写next()来代表允许路由跳转,如果写了就必须写next(),否则路由是不会生效的。 } }
The above function will be triggered whenever the route changes. We can reload the page data in this function. If the page structure changes significantly, it is recommended to create a separate new page.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to use EL expressions to obtain context parameter values in JS
JS moves the left list to the right List function
Use of el expression in js and non-empty judgment method
The above is the detailed content of Solve the problem of multiple Vue routes sharing one page. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



One of the internet connection related issues seen on Windows 11/10 computers is the “No internet, secure” error message. Basically, this error message indicates that the system is connected to the network, but due to issues with the connection, you are unable to open any web pages and receive data. You may encounter this error while connecting to any network in Windows, preferably when connecting to the Internet through a WiFi router that is not nearby. Normally, when you check the wireless icon in the lower right corner of your system tray, you'll see a small yellow triangle, and when you click it, a No Internet, Security message will appear. There is no specific reason why this error message occurs, but changes to configuration settings may cause your router to be unable to connect

How to implement API routing in the Slim framework Slim is a lightweight PHP micro-framework that provides a simple and flexible way to build web applications. One of the main features is the implementation of API routing, allowing us to map different requests to corresponding handlers. This article will introduce how to implement API routing in the Slim framework and provide some code examples. First, we need to install the Slim framework. The latest version of Slim can be installed through Composer. Open a terminal and

Connection and WiFi issues can be very frustrating and significantly reduce productivity. Computers use Network Time Protocol (NTP) for clock synchronization. In most cases, if not all, your laptop uses NTP to track time. If your server has lost contact due to NTP time server error message, read this article to the end to learn how to fix it. What happens when the router's time is set incorrectly? Router performance is generally not affected by incorrect time settings, so your connection may not be affected. However, some problems may arise. These include: Incorrect time for all gadgets that use the router as a local time server. The timestamps in the router log data will be wrong. if due to

Apache Camel is an Enterprise Service Bus (ESB)-based integration framework that can easily integrate disparate applications, services, and data sources to automate complex business processes. ApacheCamel uses route-based configuration to easily define and manage integration processes. Key features of ApacheCamel include: Flexibility: ApacheCamel can be easily integrated with a variety of applications, services, and data sources. It supports multiple protocols, including HTTP, JMS, SOAP, FTP, etc. Efficiency: ApacheCamel is very efficient, it can handle a large number of messages. It uses an asynchronous messaging mechanism, which improves performance. Expandable
![How to Fix iPhone WiFi Keeps Disconnecting Repeatedly [Solved]](https://img.php.cn/upload/article/000/887/227/168456214865307.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Many iPhone users have expressed disappointment with one of the serious issues they face on their iPhone. The problem is that their iPhone disconnects from Wi-Fi every now and then. This is indeed a major issue since Wi-Fi is a necessity to use most apps on your iPhone. We have thoroughly analyzed this issue and identified the factors that may be responsible and listed them below. Auto-join settings are disabled Some issues in network settings Change Wi-Fi password Changed Wi-Fi router issues After looking into these factors mentioned above, we have compiled a set of solutions that can fix disconnection issues with Wi-Fi issues iPhone. Fix 1 – Turn on Wi-Fi’s auto-join setting if Wi-Fi is not enabled

ThinkPHP6 is a powerful PHP framework with convenient routing functions that can easily implement URL routing configuration; at the same time, ThinkPHP6 also supports a variety of routing modes, such as GET, POST, PUT, DELETE, etc. This article will introduce how to use ThinkPHP6 for routing configuration. 1. ThinkPHP6 routing mode GET method: The GET method is a method used to obtain data and is often used for page display. In ThinkPHP6, you can use the following

The routes mentioned here are those above one thousand yuan, and we won’t talk about those below one thousand yuan. Nowadays, many enterprise routers say they have such a function, but such a function requires a prerequisite, that is, the computer must be directly connected to the router. If it is separated by a switch, these functions will be useless to the computer. Problems such as broadcast storms and ARP spoofing in the LAN are very common problems. They are not big problems, but they are very annoying. It is not difficult to solve broadcast storms, ARP spoofing or network loops. The difficulty lies in how to detect these problems. Recommend the "Buddha Nature" plug-in for our system. The reason why we say "Buddha nature" is because this detection function is based on Internet behavior management and the core of network monitoring data analysis, and only Internet behavior management can do it. It should have been placed in

Find WiFi password on Windows 11: Is it easy? Yes, you can easily view your saved WiFi passwords in Windows 11 using any of the methods mentioned below. You need administrator rights to view saved WiFi passwords on a specific device. Additionally, in some cases, devices paired with the router using WPS may not display the decrypted password. How to View Your WiFi Password on Windows 11 in 4 Easy Ways Here’s how to view your saved WiFi password in Windows 11. Follow any of the methods below based on your preferences and requirements. Method One: Use Control Panel to View WiFi Password
