-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'This' object inside vue instance methods is undefined #6
Comments
@CaptainYouz This happens because the ES6/2015 arrow function syntax ( To fix this, you'll need to use a normal function declaration: created: function () {
console.log('created', this);
}, Or, my personal preference is the ES6/2015 shorthand, which does the same as above: created () {
console.log('created', this);
}, |
Thanks for the explanation ! |
great! |
but |
Thanks a lot!!! |
how are you dealing with methods you need to bind to |
@theluk You don't need to do anything special. Just wrapping the function with debounce should work, e.g.: myMethod: debounce(
function () {
// `this` is the app/component instance here
},
500
) |
Hi !
I have also tested on the browserify vuejs-templates and i have the same error.
I followed the README and have set up a new project using vue-cli browserify, but when i'm trying to reach the 'this' object inside vue instance method (created, beforeCompile...), it always return undefined into the console.
Here is an example when i modify the script part of the App.vue file (it's the only one that i modified).
On each log, this is undefined.
I'm am missing something ?
Configuration: Macbook Pro on Chrome v50.0.2661.75 (64-bit)
The text was updated successfully, but these errors were encountered: