useCssVar
Manipulate CSS variables
Demo
Usage
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' })
Type Declarations
typescript
export interface UseCssVarOptions extends ConfigurableWindow {
initialValue?: string
/**
* Use MutationObserver to monitor variable changes
* @default false
*/
observe?: boolean
}
/**
* Manipulate CSS variables.
*
* @see https://vueuse.org/useCssVar
* @param prop
* @param target
* @param options
*/
export declare function useCssVar(
prop: MaybeRefOrGetter<string>,
target?: MaybeElementRef,
options?: UseCssVarOptions,
): Ref<string>
Source
Contributors
Anthony Fu
丶远方
Antério Vieira
Waleed Khaled
木荣
JD Solanki
btea
Alex Kozack
Changelog
v10.2.0
on 6/16/2023v10.0.2
on 4/14/2023v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue
v10.0.0-beta.0
on 3/14/2023