getComputedStyle获取元素样式值
作者:互联网
html:
<style> .div { width: 200px; height: 200px; background-color: greenyellow; } </style> </head> <body> <div class="div">一些文字</div> <script> const div = document.getElementsByClassName('div')[0] const style = getComputedStyle(div) console.log(style) console.log(style.backgroundColor) // rgb(173, 255, 47) </script> </body>
vue:
mounted() { const ref = this.$refs.h1Ref const style = getComputedStyle(ref) console.log(style) console.log(style.color) ref.classList.add('aa') }
标签:style,const,log,样式,getComputedStyle,获取,console,div 来源: https://www.cnblogs.com/wuqilang/p/15332741.html