Vue 2.0 mounted executes the cause of the problem twice (there is a personal explanation)

20180828 content add:
my code directory structure is like this

-src
--conponents_mobile
---bb.vue
--conponents_pc
---bb.vue

then use routing to determine whether to move or pc to enter, using components in different folders, is it possible that two files with the same name in two component folders will appear to be loaded twice?

<template>
    <div class="a">
        <bb v-show="registerComponentShow"></bb>
        <cc v-show="projectComponentShow"></cc>
    </div>
</template>

as in the above structure, the mounted life cycle in one of my components, bb, has been called twice, and I wonder if it is because this component has been rendered twice?
then I changed it to the following

<template>
    <div class="a">
        <bb v-if="registerComponentShow"></bb>
        <cc v-if="projectComponentShow"></cc>
    </div>
</template>

so that the mounted in bb will not be called twice.

my problem is that for a component, if you add v-show to it, it renders < bb > < / bb > for the first time and then determines whether v-show is true, or not, so it looks like mounted has been executed twice.

look forward to your advice, thank you.

2018.9.21
just remembered that I should talk about the follow-up. In fact, I made it clear a few weeks ago. In fact, the problem is that the components are applied and the components are loaded directly, so I can see that they have been executed twice.
Optimization method: lazy load is used now, and load only when needed. You can use v-if or route control to redirect, and just configure webpack.

May.05,2021

Source address: https://github.com/vuejs/vue/blob/dev/dist/vue.js
you can search v-show v-if to have a look.


dude, mounted is only executed once in the life cycle. I don't understand your question. To put it simply, the code will not be executed. The v-show executes, and here we are talking about the code of the package in the judgment condition. Second, you can check whether the code is caused by other reasons.


make sure the component is used once, and then mounted declares that the cycle executes twice?
this is very unreasonable. It is estimated that it is still a code writing problem. Please post the complete code

.
Menu