简体   繁体   English

Vue keep-alive 在 Quasar 中不起作用,挂载的钩子总是使用 $router.back() 调用

[英]Vue keep-alive not working in Quasar, mounted hook is always called using $router.back()

I have a Quasar app where I would like to cache certain pages using keep-alive for the following scenario: User navigates from home page to Page 1, then from Page 1 user navigates to Page 2, then user goes back using $router.back() to Page 1 from Page 2, in current scenario the mounted() hook is ran again in Page 1 and the page re-rendered making another API call which is not necessary at all.我有一个 Quasar 应用程序,我想在以下情况下使用 keep-alive 缓存某些页面:用户从主页导航到第 1 页,然后从第 1 页用户导航到第 2 页,然后用户使用 $router.back 返回() 从第 2 页到第 1 页,在当前情况下,mounted() 钩子在第 1 页中再次运行,并且页面重新渲染,进行另一个 API 调用,这根本没有必要。 My current implementation looks like this:我当前的实现如下所示:

  <q-page-container class="overflow-auto">
    <keep-alive>
      <router-view :key="$route.fullPath"></router-view>
    </keep-alive>
  </q-page-container>

I have setup the name property in the routes and also in the page itself.我已经在路由和页面本身中设置了 name 属性。 I also tried using include="Home,Workout " but the result is same, the mounted hook runs each time and the page is re-rendered.我也尝试过使用include="Home,Workout " 但结果是一样的,挂载的钩子每次都会运行并且页面被重新渲染。 I also need the page to stay alive so I can change the scroll behavior, scroll back to where the user was before he left Page 1. That is remembered I can see the console log for example showing y:883 but since the page is re-rendered it ends up at the top again.我还需要页面保持活动状态,以便我可以更改滚动行为,滚动回用户离开页面 1 之前的位置。记住了我可以看到控制台日志,例如显示y:883但由于页面重新- 渲染它再次出现在顶部。 Worth to mention maybe that I am using router hash mode?值得一提的是,也许我正在使用路由器 hash 模式?

What you are doing is wrong,if you want to stay alive youre page and dont refresh, you can do this... vue js is Component Axis, now you create mother component and page1 and page2 is children that import in mother component then you and swich to pag1 and page2 whith handeling v-if and your page dont refresh, you cant chnage route without refresh but you can use query to set in route你在做什么是错误的,如果你想保持你的页面并且不刷新,你可以这样做...... vue js是组件轴,现在你创建母组件,page1和page2是在母组件中导入的子组件然后你并切换到 pag1 和 page2 处理 v-if 并且您的页面不刷新,您无法在不刷新的情况下更改路由,但您可以使用查询来设置路由

all the time you change route then component render and mounted call一直更改路由然后组件渲染和挂载调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM