$el is undefined while $ref has a the object in Vuejs 3

Viewed 483

I'm trying to get a reference to the element of a textbox but $el is undefined while its $ref has the object.

What am i doing wrong here....I over-simplified my code to bring out the question. Thanks!

    app.component('lit-entry', {
        template:
            /*html*/
            `
    <div>
    
    {{ message }}
    
    <input v-model="favoriteColor" type="textbox" ref="refColor" />
    
    </div>
    
    `,
        data() {
            return {
               message :"Hey there!",
                favoriteColor:"Blue"
            }
           
        }
        , mounted() {
          
            debugger;
            var x = this.$refs.refColor.$el;  
           //refColor has a value but $el is undefined?!?             
    
        }
    
    });
1 Answers

For components with ref, a ref is component instance, $el property is DOM element.

For elements, which input is, a ref is DOM element itself, it's not supposed to have $el property.

Related