You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Inertia.js preserveScroll不生效:更新print_flag后页面自动回顶

解决Inertia.js中preserveScroll不生效的问题

核心问题:拼写错误

你的Vue代码里把preserveScroll拼写成了preverseScroll,这是配置不生效的直接原因,修正后的代码如下:

setPrintFlag(vinylRecord) {
  this.$inertia.put(route('vinylRecords.updatePrintFlag', vinylRecord.id),
    {
      print_flag: !vinylRecord.print_flag
    },
    {
      preserveState: true,
      preserveScroll: true // 修正拼写错误
    }
  )
}

额外排查点(若修正后仍有问题)

  • 后端返回逻辑:使用return back()可能导致页面重新加载,可尝试返回明确的列表页路由,比如return Inertia::location(route('vinylRecords.index')),确保状态正确传递。
  • 组件自身逻辑:检查列表组件是否存在强制滚动到顶部的代码(比如mounted钩子中设置document.documentElement.scrollTop = 0),或因key值变化导致组件完全重渲染。
  • 版本兼容性:确认使用的Inertia.js版本为稳定版,部分旧版本存在preserveScroll的功能bug,必要时升级依赖。

内容的提问来源于stack exchange,提问作者Peter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 15:35:38