simplesmiler / vue-focus

A reusable focus directive for reusable Vue.js components
MIT License
406 stars 40 forks source link

Vue 2.0 - Uncaught TypeError: Cannot read property 'focus' of undefined. #6

Closed nueverest closed 7 years ago

nueverest commented 8 years ago

I realize that I'm pushing the limits here by trying to use this code snippet in Vue 2.0.

That said, line 13 self.el.focus(); produces an error under Vue 2.0.

Uncaught TypeError: Cannot read property 'focus' of undefined. and the nextTickHandler is identified in the vue 2.0 JS file.

var focusAuto = {
    priority: 100,
    bind: function() {
        var self = this;
        this.bound = true;

        var Vue__default = 'default' in Vue ? Vue['default'] : Vue;
        Vue__default.nextTick(function() {
            if (self.bound === true) {
                self.el.focus();
            }
        });
    },
    unbind: function(){
        this.bound = false;
    }
};
simplesmiler commented 7 years ago

Hi! Sorry for taking so long to respond. I've opened an 2.0 support issue.