VueJs getting an element within a component

Snewedon picture Snewedon · May 8, 2016 · Viewed 146.1k times · Source

I have a component, how can I select one of its elements?

I'm trying to get an input that is within this component's template.

There could be multiple components so the queryselector must only parse the current instance of the component.

Vue.component('somecomponent', {
    template: '#somecomponent',
    props: [...],

   ...

    created: function() {
        somevariablehere.querySelector('input').focus();
    }
});

Thanks in advance

Answer

tariqdaouda picture tariqdaouda · Mar 5, 2017

vuejs 2

v-el:el:uniquename has been replaced by ref="uniqueName". The element is then accessed through this.$refs.uniqueName.