咱們雖然使用vue的時候是不會去操做它的dom的。可是有些狀況下咱們也不得不這麼作, 那麼咱們應該如何處理這種狀況呢? 咱們使用 ref 去綁定到 div中,以後咱們 經過 this.$refs (獲取到 vue中 全部的引用) 下面是一個例子:html
html: <div id="app"> <div ref='hello' @click="handleClick" > hello world </div> </div> js: // 在Vue中如何操做 dom 呢? // ref var vm = new Vue({ el: "#app", methods: { handleClick: function(){ // vue 中全部的引用 this.$refs.hello // 經過獲取到 dom 節點 咱們就能夠去獲取它的內容 console.log(this.$refs.hello.innerHTML); } } })