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
This article shares with you the Ubuntu server ve...
The method of obtaining the position of the point...
Gird layout has some similarities with Flex layou...
Table of contents Install mockjs in your project ...
Preface Recently, I took over a client's nati...
MySQL 8 Windows version zip installation steps (d...
1. <select style="width:195px" name=&...
Development Trends: html (Hypertext Markup Languag...
01 Winter Flakes (Individual only) 02 Snowtop Cap...
Business scenario: querying tables in different d...
I'm currently learning about MySQL optimizati...
1. In the previous chapter, we learned that we ca...
I have just come into contact with and become fam...
The questions encountered in Baidu interviews nee...
After learning the basic operations of Docker, we...