Vue提供操作DOM的方法


<div  ref="wrapper">
Vue.js 提供了我們一個獲取 DOM 對象的接口—— vm.$refs。在這里,我們通過了 this.$refs.wrapper訪問到了這個 DOM 對象,並且我們在 mounted 這個鈎子函數里,this.$nextTick 的回調函數中初始化
因為 Vue 是數據驅動的, Vue 數據發生變化(
this.data = res.data)到頁面重新渲染是一個異步的過程,我們的初始化時機是要在 DOM 重新渲染后,所以這里用到了 this.$nextTick,當然替換成 setTimeout(fn, 20) 也是可以的。
this.$nextTick(() => {
    console.log(this.$refs.wrapper)
    this.$refs.wrapper.style.color='red'
})

 另外 this.$el 可以獲取body下所有DOM節點

父頁面獲取子組件的所有屬性

<moduleListMoney  ref='com' ></moduleListMoney>

this.$refs.com.loder2 = false

更改組件 子組件 moduleListMoney 某個元素中有 loder2 變量的值

this.$refs.com 獲取組件 moduleListMoney 所有元素的值

 獲取 child下面的節點

this.$refs['comImg'].childNodes

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM