Answer the question
In order to leave comments, you need to log in
Why is the Vue component not re-rendering?
There is a component, relatively speaking, StepComponent, which is responsible for the page `/steps`
<template>
<div>
<b-row v-show="currentStep === 1">
</b-row>
<b-row v-show="currentStep === 2">
</b-row>
</div>
</template>
<template>
<div v-bind:class="{ active: searchOpen }">
<input type="text" v-model="code" />
<button v-on:click="openStep">
</button>
</div>
</template>
<script>
export default {
data() {
return {
code: ""
};
},
methods: {
openScan() {
// обновляем свойство принудительно, чтобы обновить <router-view>
// https://laracasts.com/discuss/channels/vue/vue-2-reload-component-when-same-route-is-requested
this.$router.forceReloadKey = new Date().getTime();
this.$router.push({ path: "/steps", params: { currentStep: 2 } });
}
}
};
</script>
<template>
<div id="app">
<component :is="layout">
<transition name="fade" mode="out-in">
<router-view :key="$route.forceReloadKey"></router-view>
</transition>
</component>
</div>
</template>
export default {
components: { },
data() {
return {
currentStep: 1
};
},
mounted() {
// срабатывает только раз
console.log("mounted");
},
created() {
// срабатывает только раз
console.log("created");
},
methods: {}
watch: {
"this.$router.forceReloadKey"() {
// не срабатывает при обновлении forceReloadKey из другого компонента
console.log("forceReloadKey");
}
}
};
Answer the question
In order to leave comments, you need to log in
you should use instead of , as v-show only toggles display: block/none, while v-if re-renders the component, calling the lifecycle hooks v-if
v-show
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question