Calling methods inside of data() is not allowed in 2.x?
See original GitHub issueVue.js version
2.1.0
Reproduction Link
Steps to reproduce
Call any method inside of data()
function
What is Expected?
Method should be called (just like in 1.x)
What is actually happening?
Uncaught TypeError: %method% is not a function
is thrown
We are migrating from vue 1.0.28 to 2.x and seems that data()
behaviour changed but there’s no info in migration guide, vue-migration-helper also says nothing about this. Is this a bug or possibility of calling methods inside data()
was removed?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:6
Top Results From Across the Web
VueJS accessing a method from another method
I was making mistake, I made an ajax call and was trying to access app methods via this , and var self =...
Read more >TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >Functions - Advanced R. - Hadley Wickham
Functions. Functions are a fundamental building block of R: to master many of the more advanced techniques in this book, you need a...
Read more >Defining and Calling Methods | Defining and Using Classes
Describes the rules and options for creating and executing methods in InterSystems IRIS® classes.
Read more >Methods - C# Guide | Microsoft Learn
You invoke a static method by referencing the name of the type to which the method belongs; static methods don't operate on instance...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Then why this issue is closed?
This does work. Pay attention to the posted jsfiddle. It opened with Javascript in the “no library (pure JS)” mode. As soon as I picked VueJS 2.2.1 from there (confirmed to work on 2.6.10 as well), it started giving the expected result.
If you still have issues with this in your code, pay special attention to the
data
object. Like in the posted jsfiddle, it needs to be returned from a function and not directly declared with the Javascript object notation as a property. If you do this, calling functions from within should work as well. You’ll easily run into limitations with this though; the VueJS state will be beforecreated()
has been called.