解决TS报错Property ‘style‘ does not exist on type ‘Element‘
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element

·
在使用queryselector获取一个dom元素,编译时却报错说property 'style' does not exist on type 'element'。
原因:这是typescript的类型检查导致的,需要在querySelector方法前面加个类型断言。
let frameContainObj = document.getElementById("model_view_container")
let iframeObj= <HTMLElement>frameContainObj.querySelector("#modelView");
iframeObj.style.height = document.documentElement.clientHeight* 0.65 + "px";
扩展:当使用queryselectorall时,可以采用如下方案:
let block = document.querySelectorAll(".block") as NodeListOf<HTMLElement>;
通过设置断言来告诉typescript编译器通过此代码




A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:21 天前 )
c345bb45
1 年前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 1 年前
更多推荐
所有评论(0)