Skip to content

useTextDirection

类别
导出体积
821 B
上次更改
2 minutes ago

元素文本的响应式 dir

示例

This paragraph is in English and correctly goes left to right.


单击以更改方向

用法

ts
import { useTextDirection } from '@vueuse/core'

const dir = useTextDirection() // Ref<'ltr' | 'rtl' | 'auto'>

默认情况下,当将 dir rtl 应用于 html 标签时,它返回 rtl 方向,例如:

html
<!--ltr-->
<html>
  ...
</html>

<!--rtl-->
<html dir="rtl">
  ...
</html>

选项

ts
import { useTextDirection } from '@vueuse/core'

const mode = useTextDirection({
  selector: 'body'
}) // Ref<'ltr' | 'rtl' | 'auto'>

类型声明

typescript
export type UseTextDirectionValue = "ltr" | "rtl" | "auto"
export interface UseTextDirectionOptions extends ConfigurableDocument {
  /**
   * 适用于的目标元素的 CSS 选择器
   *
   * @default 'html'
   */
  selector?: string
  /**
   * 使用 MutationObserver 观察 `document.querySelector(selector)` 的变化
   *
   * @default false
   */
  observe?: boolean
  /**
   * 初始值
   *
   * @default 'ltr'
   */
  initialValue?: UseTextDirectionValue
}
/**
 * 元素文本的响应式方向。
 *
 * @see https://vueuse.org/useTextDirection
 */
export declare function useTextDirection(
  options?: UseTextDirectionOptions,
): WritableComputedRef<UseTextDirectionValue, UseTextDirectionValue>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
iChengbo
Anthony Fu
Eyal Peleg
Nestor Vera

更新日志

没有最近的更新日志