Skip to content

useBrowserLocation

反应式浏览器位置

¥Reactive browser location

注意:如果你使用的是 Vue Router,请改用 Vue Router 提供的 useRoute

¥NOTE: If you're using Vue Router, use useRoute provided by Vue Router instead.

示例

Input and hash will be changed:
trigger: 'load'

用法

¥Usage

js
import { useBrowserLocation } from '@vueuse/core'

const location = useBrowserLocation()

组件用法

¥Component Usage

vue
<UseBrowserLocation v-slot="{ location }">
  Browser Location: {{ location }}
</UseBrowserLocation>

类型声明

显示类型声明
typescript
export interface BrowserLocationState {
  readonly trigger: string
  readonly state?: any
  readonly length?: number
  readonly origin?: string
  hash?: string
  host?: string
  hostname?: string
  href?: string
  pathname?: string
  port?: string
  protocol?: string
  search?: string
}
/**
 * Reactive browser location.
 *
 * @see https://vueuse.org/useBrowserLocation
 */
export declare function useBrowserLocation(options?: ConfigurableWindow): Ref<
  {
    readonly trigger: string
    readonly state?: any
    readonly length?: number | undefined
    readonly origin?: string | undefined
    hash?: string | undefined
    host?: string | undefined
    hostname?: string | undefined
    href?: string | undefined
    pathname?: string | undefined
    port?: string | undefined
    protocol?: string | undefined
    search?: string | undefined
  },
  | BrowserLocationState
  | {
      readonly trigger: string
      readonly state?: any
      readonly length?: number | undefined
      readonly origin?: string | undefined
      hash?: string | undefined
      host?: string | undefined
      hostname?: string | undefined
      href?: string | undefined
      pathname?: string | undefined
      port?: string | undefined
      protocol?: string | undefined
      search?: string | undefined
    }
>
export type UseBrowserLocationReturn = ReturnType<typeof useBrowserLocation>

源代码

源代码示例文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号