【问题标题】:InertiaJS loses remember when I'm back on the page当我回到页面时,InertiaJS 会忘记
【发布时间】:2022-06-10 20:27:01
【问题描述】:

我在 Vue 中使用 Inertia JS 和 Options API。

我有一个需要记住的属性,所以当我在一个方法中设置它时:

Inertia.remember(booth, 'active')

然后在 created 或 mounted 挂钩上,我将像这样恢复它:

this.active = Inertia.restore('active') ?? 4;

刷新页面时ONCE。在第二次刷新时,它会失去记忆并进入默认 4。我想我也必须在 mounted 挂钩中记住它?

但是,当我导航到另一个页面(与此组件无关)然后使用惯性链接返回第一页时,状态总是丢失,restore() 返回undefined。

我错过了什么?

【问题讨论】:

    标签: laravel vue.js laravel-8 vuejs3 inertiajs


    【解决方案1】:

    你可以试试这样,应该可以的

    beforeUnmount() {
     Inertia.remember(booth, 'active')
    
    },
    mounted() {
     this.active = Inertia.restore('active') ?? 4;
    
     },
    

    【讨论】:

      猜你喜欢
      • 2023-01-05
      • 1970-01-01
      • 2015-03-08
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 2015-06-29
      • 1970-01-01
      相关资源
      最近更新 更多