【问题标题】:Watching route change with Laravel Inertia使用 Laravel Inertia 观察路线变化
【发布时间】:2021-03-16 19:14:03
【问题描述】:

使用新的 Inertia Laravel 堆栈 - 你如何观察路线变化?

我正在尝试做一些非常简单的事情,例如:

watch: {
  route () {
    console.log('You changed route')
  }
}

我没有找到任何有关这方面的信息。

【问题讨论】:

  • 你在哪里将你的路由信息​​传递给 Vue?

标签: laravel vue.js inertiajs


【解决方案1】:

您需要收听start 事件。

import { Inertia } from '@inertiajs/inertia'

Inertia.on('start', (event) => {
  console.log(`The route changed to ${event.detail.visit.url}`)
})

注意start 事件在加载完成之前触发。如果您想在显示新页面后收到通知,请使用success 事件。

欲了解更多信息,请查看https://inertiajs.com/events

【讨论】:

    【解决方案2】:

    你也可以这样做:

    watch: {
      '$page.url': function (newUrl, oldUrl) {
        console.log(newUrl)
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-23
      • 1970-01-01
      • 2021-04-30
      • 2019-01-24
      • 2019-03-23
      • 1970-01-01
      • 2020-07-29
      • 1970-01-01
      相关资源
      最近更新 更多