useScriptEventPage

useScriptEventPage 函数的 API 文档。

访问当前页面的标题和路径,并在它们变化时触发事件。

签名

function useScriptEventPage(callback?: (title: string, path: string) => void): Ref<{ title: string, path: string }> {}

参数

  • callback(可选) - 当页面标题或路径发生变化时调用的函数。

返回值

一个包含当前页面标题和路径的 ref。

示例

  • 在元素可见时加载脚本。
<script setup lang="ts">
useScriptEventPage((ctx) => {
  console.log(ctx.title, ctx.path)
})
</script>