我正在尝试使用计算出的变量值设置css属性的值。
我有两个班.v-table__overflow
和.v-datatable__actions
。我想获取.v-table__overflow
的width值,并在.v-datatable__actions
中将此值设置为此类的width值。
我收到此错误:
未捕获的TypeError:无法读取未定义的属性'setProperty'
var dtoverflow = document.querySelector('.v-table__overflow')
const style4 = getComputedStyle(dtoverflow);
var dtoverflowWidth = style4.width
var dtActions = document.querySelector('.v-datatable__actions')
const style5 = getComputedStyle(dtActions);
var dtActionsWidth = style5.width;
dtActionsWidth.style.setProperty('width', '--dtoverflowWidth');
答案 0 :(得分:1)
尝试这种方式
var dtoverflow = document.querySelector('.v-table__overflow')
var dtoverflowWidth = getComputedStyle(dtoverflow).width;
var dtActions = document.querySelector('.v-datatable__actions')
var dtActionsWidth = getComputedStyle(dtActions).width;
dtActions.style.width = dtoverflowWidth;
在最后一行中,您还使用dtActionsWidth
而不是dtActions
出现了错字。