Skip to content

useNavigatorLanguage

Category
Export Size
681 B
Last Changed
2 months ago

响应式地获取 navigator.language

Demo

Supported: false

Navigator Language:
您的浏览器不支持 Navigator.language API。

使用方法

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

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

    watch(language, () => {
      // 监听值的变化
    })

    return {
      language,
    }
  },
})

Type Declarations

Show Type Declarations
typescript
export interface NavigatorLanguageState {
  isSupported: ComputedRef<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: ShallowRef<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>

Source

SourceDemoDocs

Contributors

Anthony Fu
丶远方
IlyaL
Anthony Fu
Fernando Fernández
Alex Liu
vaakian X
Jelf
WuLianN
Michael J. Roberts

Changelog

dd316 - feat: use passive event handlers everywhere is possible (#4477)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

Released under the MIT License.