在元素的 ie11/Edge 中设置宽度 - 在严格模式下不允许分配给只读属性

Setting width in ie11/Edge on element - assignment to read-only properties is not allowed in strict mode

我正在选择一个元素,我需要根据某些规则更改元素的大小,这在主流浏览器中都可以正常工作,但在 ie11/Edge 中它不起作用。

this.visContainer = this.$element[0].querySelector('.am-visualization-render-area__vis-container');

这是哪里出错了我正在尝试将一个值设置为只读 属性

 const visContainerBounds = this.visContainer.getBoundingClientRect();
 visContainerBounds.width -= this.marginHorizontal;
 visContainerBounds.height -= this.marginVertical;

这个returns错误

assignment to read-only properties is not allowed in strict mode

我也试过了

this.visContainer.clientWidth -= this.marginHorizontal;
this.visContainer.clientHeight -= this.marginVertical;
const visContainerBounds = this.visContainer.getBoundingClientRect();

根据我的发现,这是由 ie 和 edge 遵循 ECMAScript5 标准造成的,chrome ff safari 不在这种情况下。

我的问题是如何在不引发此错误的情况下设置元素的宽度值?感谢任何帮助。

不能直接设置样式吗?喜欢:

this.visContainer.style.width="100px";