useTextDirection
元素的文字的響應式 dir 屬性。
範例
這段文字是英文,並且正確地從左到右顯示。
點擊以更改方向
用法
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 Selector for the target element applying to
*
* @default 'html'
*/
selector?: string
/**
* Observe `document.querySelector(selector)` changes using MutationObserve
*
* @default false
*/
observe?: boolean
/**
* Initial value
*
* @default 'ltr'
*/
initialValue?: UseTextDirectionValue
}
/**
* Reactive dir of the element's text.
*
* @see https://vueuse.dev.org.tw/useTextDirection
*/
export declare function useTextDirection(
options?: UseTextDirectionOptions,
): WritableComputedRef<UseTextDirectionValue, UseTextDirectionValue>
原始碼
貢獻者
更新日誌
v12.0.0-beta.1
於 2024/11/21