Problem description: There are two pages A and B, each page has a Later I found out that it was because of the use of keep-alive. Keep-alive will always keep the Vue instance in memory, so the Vue instance always exists and the corresponding watchers are always effective. After searching for relevant information, I found that many people have encountered this problem. Finally, I found the following two solutions: Solution 1 Determine whether to execute watch: someValue(newValue, oldValue) { if (this.$route.fullPath === 'A page routing path') { // do something } } } Solution 2 Add a flag parameter to determine whether the page is in the active state. Components using keep-alive caching will only trigger { data () { return { activatedFlag: false }; }, watch: 'someValue'(val) { if(val && this.activatedFlag) { this.getlist(); } } }, activated () { this.activatedFlag = true; }, deactivated () { this.activatedFlag = false; } } If there are many pages and the function names in each page are inconsistent, you can remove the watch part of the above code and write it into a mixin, and then import it on the required page. import activeFlag from "@/mixin/activeFlag"; export default { mixins: [activeFlag], watch: 'someValue'(val) { if(val && this.activatedFlag) { this.getlistA(); this.getlistB(); } } }, } The above are the details of the two solutions to the problem of repeated triggering of functions in the vue project watch. For more information on the solution to repeated triggering of vue watch functions, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to install multiple mysql5.7.19 (tar.gz) files under Linux
>>: Weird and interesting Docker commands you may not know
Example Usage Copy code The code is as follows: &l...
Preface This article mainly introduces the releva...
First of all, this post is dedicated to Docker no...
In MySQL, fields of char, varchar, and text types...
Table of contents 1. Preparation 2. Introduction ...
This article shares the specific code for JavaScr...
The project scaffolding built with vue-cli has al...
Table of contents Preface How does antd encapsula...
Preface: Docker is an open source application con...
MySql Download 1. Open the official website and f...
This article example shares the specific code of ...
Mac latest version of MySQL 8.0.22 password recov...
1. Preparation before installation 1. Download th...
The original code is this: <div class='con...
1. Download the alpine image [root@DockerBrian ~]...