$el 用於獲取vue掛載的實例的dom對象,在mounted生命週期中才有效。vue
<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>