Javascript evaluation error in LESS file

2019-09-01 05:49发布

I have the follwoing code in less file:

@winheight: unit(`document.documentElement.clientHeight`, px);

and I want to call that variable in:

.test {
    height: ~"@{winheight}";
}

But I still get an error at variable @winheight:

LESS: JavaScript evaluation error: 'TypeError: 'document.documentElement.clientHeight' is null or not an object'

How to fix this? Where is my mistake ?

1条回答
The star\"
2楼-- · 2019-09-01 06:23

document.documentElement.clientHeight can only exists when running less.js, in browser see: http://lesscss.org/usage/#using-less-in-the-browser.

In all other situations your Less code will be compiled into static CSS code.

查看更多
登录 后发表回答