欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue.js -- 获取dom元素的样式(非行内样式)

程序员文章站 2022-06-21 10:44:41
...

在vue中获取dom元素的样式:

this.$refs.menuList.style.top;

这种获取方式是只能获取到元素的行内样式的。

this.$refs.menuList.getBoundingClientRect().top;

而下面这种方式是可以获取到外联样式表的样式的,不过这种是获取到计算过的样式。

let menuList = document.querySelector('.menuList');
let top = window.getComputedStyle(menuList).top;

这种方式获取到的是正常值。

转载于::https://blog.csdn.net/qq_40851816/article/details/90671361

相关标签: vue专栏 vue