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

 

posted @ 2018-05-15 20:51  Model-Zachary  阅读(7128)  评论(0编辑  收藏  举报