一、 $ref?
在Vue中想直接獲取元素對象或子組件的實例的時候,可以給元素或者組件綁定一個ref 的 attribute屬性。
1. 綁定到元素上
<h2 ref="title">哈哈哈</h2>
2. 綁定到組件實例上
<NavBar ref="navbar" :titles="titles"></NavBar>
3. 獲取元素/組件實例
· 獲取元素 this.$refs.title
· 獲取組件實例 this.$refs.navbar
· 獲取組件實例中的屬性 this.$refs.navbar.name
· 執(zhí)行組件實例中的方法 this.$refs.navbar.navBarClick()

二、 $parent?
1. 訪問父組件元素
this.$parent.titles
2.?執(zhí)行父組件中的方法?
this.$parent.btnClick()
三、 $root
1. 訪問根組件元素
this.$root.titles
2.?執(zhí)行根組件中的方法?
this.$root.btnClick()

四、$el
獲取組件的根元素
this.$refs.navbar.$el