How to solve the problem of vue nested routing and repeated calls from the parent?

vue has the following route nesting:
/ > app.vue > a.vue > b.vue

app.vue is the ingress, an is a level 2 route, and b is a child of a

when accessing the b route, the request written in an and some column hook events will be called repeatedly. What should I do?

for example, if there is a data request in created in app.vue, the hook in app.vue will be called repeatedly when accessing an or b.

  1. is my idea of placing it wrong? Or is that what vue itself can only do?
  2. is there a solution?

theoretically, switching nested routes does not trigger the created method in the parent component.

maybe it's because you set up keep-alive and add some judgments to reselect the rendered page.


according to your description, if you open the application directly and access B directly through url, then all the created on the entire link will definitely be called, which is inevitable. If you open it first, and then jump to b, then the created of app and a will not be called, which is also inevitable


I have this problem, too. Every time I enter a nested child route, the life cycle of the parent route goes through again, causing the components in the parent route to be created repeatedly. Sometimes two instances of components within a parent route are created.

after searching for a while, it turns out that the parent route itself is caused by < keep-alive > .

remove < keep-alive > and everything is fine.

my structure is like this
App.vue > parent.vue > child.vue
url is like this when accessing
http://localhost:3000/-sharp/parent/child

The

problem lies in App.vue

.
<keep-alive>
  <router-view ></router-view> // parent.vue
</keep-alive>

remove keep-alive

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e47728-44c34.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e47728-44c34.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?