Svelte:<svelte:window bind:innerHeight /> 在 window 调整大小时无法使用 div 中的样式属性

Svelte: <svelte:window bind:innerHeight /> is not working with style attribute in div on window resize

在 window 调整大小时,我尝试使用 svelte 特殊元素 <svelte:window bind:innerHeight /> 在 div 元素中添加动态高度作为样式 属性 但我没有得到我正在寻找正确的结果,有没有我遗漏的东西。

代码:-

<script>
    var innerHeight;
</script>

<svelte:window bind:innerHeight={innerHeight} />

<div style="height: {innerHeight};">
    <h1>window height : {innerHeight}</h1>
</div>

输出:-

enter image description here

提前致谢

innerHeight是少了一个单位的值,为了像你一样使用它,你必须自己将单位添加到样式标签中'

style="height: {innerHeight}px;"

(注意额外的 px