Answer the question
In order to leave comments, you need to log in
How to change another component on path change (vue-router)?
Hello everyone) there was a problem)
I have such a structure
<div id="app">
<app-header></app-header>
<transition name="fade">
<router-view></router-view>
</transition>
</div>
<router-link to="/result"
tag="div"
class="progress__item-text">
Переход
</router-link>
<div class="header__tabs"
v-if="headerTab">
<...>
</div>
Answer the question
In order to leave comments, you need to log in
If the app-header relies specifically on the router and only on the router (that is, other components will not directly affect the display of any elements), then you can do it very beautifully and gracefully through computed, something like this:
computed: {
headerTab() { return this.$route.path === '/result'; }
}
I understand that you just need to keep track of when the path changes
, there is a "watch" method for this.
Therefore, in the component in which you need to monitor the paths, paste this code:
watch: {
'$route': function(){
....
}
Smoke this: https://en.vuejs.org/v2/guide/components.html#Comm...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question