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')
}