コンテンツへスキップ

useCssVar

カテゴリ
エクスポートサイズ
820 B
最終変更
先週

CSS変数を操作する

デモ

サンプルテキスト,
サンプルテキスト, --color

使い方

js
import { useCssVar } from '@vueuse/core'

const el = ref(null)
const color1 = useCssVar('--color', el)

const elv = ref(null)
const key = ref('--color')
const colorVal = useCssVar(key, elv)

const someEl = ref(null)
const color2 = useCssVar('--color', someEl, { initialValue: '#eee' })

型宣言

typescript
export interface UseCssVarOptions extends ConfigurableWindow {
  initialValue?: string
  /**
   * Use MutationObserver to monitor variable changes
   * @default false
   */
  observe?: boolean
}
/**
 * Manipulate CSS variables.
 *
 * @see https://vueuse.dokyumento.jp/useCssVar
 * @param prop
 * @param target
 * @param options
 */
export declare function useCssVar(
  prop: MaybeRefOrGetter<string | null | undefined>,
  target?: MaybeElementRef,
  options?: UseCssVarOptions,
): Ref<string | null | undefined, string | null | undefined>

ソース

ソースデモドキュメント

コントリビューター

Anthony Fu
丶远方
Antério Vieira
Anthony Fu
babu-ch
Fernando Fernández
Waleed Khaled
木荣
JD Solanki
btea
Alex Kozack

変更履歴

v12.0.0-beta.1 2024年11月21日
0a9ed - feat!: Vue 2のサポートを削除、バンドルを最適化し、クリーンアップ (#4349)
v11.0.2 2024年8月24日
d0523 - fix: getComputedStyleを直接のstyleプロパティアクセスに置き換え (#4166)
v11.0.0-beta.2 2024年7月17日
fe19c - feat(useCssVars): null/undefined のプロパティを削除 (#3821)
v10.2.0 2023/06/16 リリース
9d34a - fix: 要素のクラスリストに基づいた変更を監視 (#3131)
v10.0.2 2023/04/14 リリース
7d001 - fix: モジュール参照、#2972 をクローズ
v10.0.0-beta.4 2023/04/13 リリース
4d757 - feat(types)!: MaybeComputedRefMaybeRefOrGetter にリネーム
0a72b - feat(toValue): resolveUnreftoValue にリネーム
v10.0.0-beta.0 2023/03/14 リリース
ae6e1 - feat: observe オプションを導入 (#2800)

MITライセンスの下でリリースされています。