$el 用于获取vue挂载的实例的dom对象,在mounted生命周期中才有效。

<template>
<div>
    home
    <div>啊哈哈</div>
</div>
</template>
<script>
export default {
  name: "Home",
  data () {
    return {
    };
  },
  mounted(){
      // this.$el只在mounted中才有效
    console.log(this.$el);//打印这个vue组件的dom对象
    this.$el.style.color = "red"
  }
}
</script>

 

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-07
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案