代码:
let elementById = document.getElementById('aaa');
console.log(elementById.offsetLeft)
let elements1 = document.getElementsByClassName('gantt_menu');
console.log(elements1)
控制台:
更改代码:
let elementById = document.getElementById('aaa');
console.log(elementById.offsetLeft)
let elements1 = document.getElementsByClassName('gantt_menu');
console.log(elements1[0])
控制台:
css:
<div class="gantt_group" v-for="item of taskInfo">
<div class="gantt_menu">{{ item.name }}</div>
<div class="gantt_body"
:style="{'left': mathPosition(itemBody.startDate),'width':mathGanttLength(itemBody.startDate,itemBody.endDate)}" v-for="itemBody of item.stage">
{{ itemBody.text }}
</div>
</div>
看了很多资料是由于vue没有加载出来,导致为空,但我的已经打印出来了只要使用遍历或索引就是空 ,这是博客上的解答https://blog.csdn.net/weixin_41602509/article/details/86661758https://blog.csdn.net/weixin_41602509/article/details/86661758