Skip to content

useNavigatorLanguage

反应式 navigator.language

¥Reactive navigator.language.

示例

Supported: false

Navigator Language:
The Navigator.language API is not supported in your browser.

用法

¥Usage

ts
import { useNavigatorLanguage } from '@vueuse/core'
import { defineComponent, ref } from 'vue'

export default defineComponent({
  setup() {
    const { language } = useNavigatorLanguage()

    watch(language, () => {
      // Listen to the value changing
    })

    return {
      language,
    }
  },
})
js
import { useNavigatorLanguage } from '@vueuse/core'
import { defineComponent } from 'vue'
export default defineComponent({
  setup() {
    const { language } = useNavigatorLanguage()
    watch(language, () => {
      // Listen to the value changing
    })
    return {
      language,
    }
  },
})

类型声明

显示类型声明
typescript
export interface NavigatorLanguageState {
  isSupported: Ref<boolean>
  /**
   *
   * ISO 639-1 standard Language Code
   *
   * @info The detected user agent language preference as a language tag
   * (which is sometimes referred to as a "locale identifier").
   * This consists of a 2-3 letter base language tag that indicates a
   * language, optionally followed by additional subtags separated by
   * '-'. The most common extra information is the country or region
   * variant (like 'en-US' or 'fr-CA').
   *
   *
   * @see https://www.iso.org/iso-639-language-codes.html
   * @see https://www.loc.gov/standards/iso639-2/php/code_list.php
   *
   */
  language: Ref<string | undefined>
}
/**
 *
 * Reactive useNavigatorLanguage
 *
 * Detects the currently selected user language and returns a reactive language
 * @see https://vueuse.org/useNavigatorLanguage
 *
 */
export declare function useNavigatorLanguage(
  options?: ConfigurableWindow,
): Readonly<NavigatorLanguageState>
export type UseNavigatorLanguageReturn = ReturnType<typeof useNavigatorLanguage>

源代码

源代码示例文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号