Does vue set the height to dom through ref does not work?

<el-col :span="7" ref="wrap"><div></div></el-col>

mounted () {
    let height =document.body.clientHeight
    console.log(height)
    console.log(this.$refs.wrap)
    // this.$refs.wrap.style.height = height
  }

the output this.$refs.wrap, is not a dom,. I don"t know what went wrong?

Mar.31,2021

this is a usage error.
ref there are two cases:
first, if you use it on a normal DOM element, the reference points to the DOM element.
second, if used on child components, the reference points to the component instance.

your case, which is the second, is applied to components, so if you want to get dom, you need to use

.
this.$refs.wrap.$el

to get the constructed and container dom node, and then set the style.

of course, if you want to set the elements in slot, then after getting the root container dom node, you can get any dom node you want through normal querySelector and other methods

if you have any more questions, you are welcome to discuss them again. ?


gets the component, and ref loads the specific DOM element


$refs.wrap gets a VUE component, not a DOM.
if you want to manipulate DOM, manually, give the node an ID, in the component, such as el-col, give an ID, and then use this.$el.querySelector (- sharpID) to get the operation.

Menu