Skip to content

Commit d680f1f

Browse files
authored
fix(useCssVar): update variable when initial (#4641)
1 parent 73e6db2 commit d680f1f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

packages/core/useCssVar/index.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ describe('useCssVar', () => {
1919
expect(el.style.getPropertyValue(color)).toBe('red')
2020
})
2121

22+
it('should work with css variables', () => {
23+
document.documentElement.style.setProperty('--rootColor', 'red')
24+
25+
const colorNoRef = useCssVar('--rootColor')
26+
27+
expect(colorNoRef.value).toBe('red')
28+
})
29+
2230
it('should use window.document.documentElement as default element if not set', async () => {
2331
const vm = mount(defineComponent({
2432
setup() {

packages/core/useCssVar/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function useCssVar(
5555
old[0].style.removeProperty(old[1])
5656
updateCssVar()
5757
},
58+
{ immediate: true },
5859
)
5960

6061
watch(

0 commit comments

Comments
 (0)