question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling methods inside of data() is not allowed in 2.x?

See original GitHub issue

Vue.js version

2.1.0

Reproduction Link

http://jsfiddle.net/ds8o0kry/

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:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:6

github_iconTop GitHub Comments

7reactions
ijunaid8989commented, Apr 10, 2019

Then why this issue is closed?

0reactions
jonasnordlundcommented, Feb 28, 2020

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 before created() has been called.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found