Skip to content

useTextDirection

元素文本的反应式 dir

¥Reactive dir of the element's text.

示例

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


Click to change the direction

用法

¥Usage

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

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

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

¥By default, it returns rtl direction when dir rtl is applied to the html tag, for example:

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

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

选项

¥Options

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

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