UNPKG

@cran/vue.use

Version:

Cranberry Vue Use Utilities

13 lines (12 loc) 423 B
import { ref, watch } from "@vue/runtime-dom"; const varmap = {}; export function useCssVar(key, defaultValue = "") { if (!varmap[key]) { const variable = varmap[key] = ref(defaultValue); const cssKey = `--${key}`; watch(variable, function onChange(value) { document.documentElement.style.setProperty(cssKey, value); }, { immediate: true, }); } return varmap[key]; }