Skip to content
On this page

useBrowserLocation

响应式获取 Location

Reactive browser location

注意:如果您使用的是 Vue Router,请改用 useRoute 获取

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

例子

trigger: 'load'

Usage

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

const location = useBrowserLocation()
import { useBrowserLocation } from '@vueuse/core'

const location = useBrowserLocation()

Component Usage

该函数还通过@vueuse/components提供了一个无渲染的组件版本。了解更多.

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

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

Type Declarations

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

Source

Category
Export Size
1.17 kB
Last Changed
last year

SourceDemoDocs

贡献者(Contributors)

日志(Changelog)

No recent changes

Released under the MIT License.