Vue 2 not working with and key

前端 未结 4 1809
旧巷少年郎
旧巷少年郎 2020-12-19 16:55

I\'m using vue-router with a series of components like tabs. Each is a tab and the space below is the . Two

4条回答
  •  时光说笑
    2020-12-19 17:39

    Have a look from what I posted here for vue 2+:

    vue.js keep-alive and router-view

    If you want to swap things around based on the route url you can add children to your routes.js file and bind off parameters that way. For example if you wanted to have your component kept alive but need the data to change from part of the path you can do something like this:

    { 
      path: 'products', component: Products, ...,
      children: [
                  { path: 'Overview/:name', props: true, component: Overview },
                  { path: 'Overview/:name/:id', props: true, component: Details }
                ]
    }
    

    You can route first to /Products, then on say user click of an image or list of whatever you want route to /Products/Overview/Memes, after the user then clicks a specific meme you could route to /Products/Overview/Memes/MrPotatoHead and have the component load data on Mr Potato Head or something to that effect.

    Its important to note that the Products component will be kept alive but the sub components will not. Even if you wrap the sub components template in keep-alive it will be destroyed:

    destroy nested keep-alive components

提交回复
热议问题