I am facing a dilemma with 4 components that are loaded based on the values of two boolean variables onePage
and currentStep
. Depending on these values, the components should either load one by one or all together.
<div v-if="!onePage">
<Component_1 v-show="currentStep === 1" @eventHandler1="someFunc()" :prop="someData1" />
<Component_2 v-show="currentStep === 2" @eventHandler2="someFunc()" :prop="someData2" />
<Component_3 v-show="currentStep === 3" @eventHandler3="someFunc()" :prop="someData3"/>
<Component_4 v-show="currentStep === 4" @eventHandler4="someFunc()" :prop="someData4" />
</div>
<div v-else class="mt-5 pt-1">
<Component_1 @eventHandler1="someFunc()" :prop="someData1" />
<Component_2 @eventHandler2="someFunc()" :prop="someData2" />
<Component_3 @eventHandler3="someFunc()" :prop="someData3"/>
<Component_4 @eventHandler4="someFunc()" :prop="someData4" />
</div>
The challenge lies in maintaining changes within each component when the value of onePage
is toggled. For example, changes made in Component1 do not persist when onePage: false, currentStep: 1
(e.g. changes to a data object) causing it to reset to default values when rendered through the v-else
condition in the second Div.