How do I use JS to get the classname, of DOM in the vue component to ensure that the acquired classname is unique?

the problem is difficult to describe. Let me give an example. For example, the following code is in the header of the page:

<template>
  <div class="header">
    ...
  </div>
</template>
<script>
export default {
  mounted: ()=>{
    document.getElementsByClassName("header")[0].style.colro="red"
  }
}
</script>
<style scoped>
  .header {
    background: -sharp999999;
  }
<style>

because scoped, is added to the above code style, you don"t have to worry about using the same classname (.header) elsewhere in the page. The .header style here must point to the header in this component. But if you want to use JS to control header style is not easy, if there is a header style elsewhere on the page, then document.getElementsByClassName ("header") [0] may not be the DOM, I want to choose. Excuse me, how can I use JS to control DOM without worrying about the style with the same name?


get dom with $refs. Link


learn about this.$el , official documents


mounted cannot use the arrow function

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf42ec-3a295.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf42ec-3a295.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?