On my main page I have drop-down menus showing v-show=showby clicking on the link @click = "show=!show", and I want to set show=falsewhen changing the route. Please advise me how to implement this.
v-show=show
@click = "show=!show"
show=false
Set observer on $routein your component as follows:
$route
watch:{ $route (to, from){ this.show = false; } }
It watches for route changes and when changing, sets showfalse
show
If you are using v2.2.0, then there is another option available for detecting changes in $ routes.
To respond to parameter changes in the same component, you can simply observe the $ route object:
const User = { template: '...', watch: { '$route' (to, from) { // react to route changes... } } }
beforeRouteUpdate, 2.2:
const User = { template: '...', beforeRouteUpdate (to, from, next) { // react to route changes... // don't forget to call next() } }
: https://router.vuejs.org/en/essentials/dynamic-matching.html
- , ,
@Watch('$route', { immediate: true, deep: true }) onUrlChange(newVal: any) { // Some action }
, @Coops ,
import { Prop, Watch } from "vue-property-decorator";
, : , VueRouter : this. $ Router.history. , :
this.$router.listen((newLocation) =>{console.log(newLocation);})
, , . $ Router.currentRoute.path , debugger
debugger
Chrome DevTools Console.
.
Instead, I use updated () the lifecycle trap that is executed each time the component data changes. Just use it, as with mount () .
mounted() { /* to be executed when mounted */ }, updated() { console.log(this.$route) }
For help, visit the documentation .
There is an updated life cycle state
Source: https://habr.com/ru/post/1686337/More articles:Writing to the same memory at the same time in a parallel loop omp - c ++graphene graphql dictionary as type - pythonDisabling implicit flow for Google OAuth (web server applications)? - oauthiOS: dynamic structure based on dependency of a static library - iosHow to check if linking to current page in Prawn is suitable - ruby | fooobar.comMongodb brings together three collections - mongodbGetModuleFileNameEx for a 32-bit process from a 64-bit process on windows 10 - windowsAngular2 + SVG: using one template for multiple components (IE fix?) - internet-explorerUNIX AWK script - memory exhausted - unixКак проверить, что класс descendent переопределяет все виртуальные методы? - inheritanceAll Articles