$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>