access methods from the vue current component

573 views vue.js

Can any one guide or suggest how to resolve this below issue. Use Case: Trying to implement notification component Scenario: I am trying to call a method or change the state of the data on triggering of event in Vue. I have defined the event listener on mounted function and trying to access one of the method.

enter image description here

Basically, the alert within event function is getting triggered, where as alert inside method is not getting triggered, and even any data manipulation is not executing even with in event function.

Where am i missing? is it incorrect to alter state within Event listener? Basically i am trying to implement notification feature which automatically disappear after few seconds

Any help is appreciated.

Thanks, Girish

answered question

1 Answer


I believe your problem is the spelling error instead of

method: {}

, use methods: {} Example:

method: {
test: function () {
alert('Inside Method');

methods: {
test: function () {
alert('inside method);

I know it does not have much to do with the question, but be careful when using the event bus, it would be as if you had a speaker, and shouted in the middle of a crowd the name of a person. Example: eventbus says Hamilton in the midst of a crowd of 10,000 people. How many Hamiltons can you have in the middle of this crowd? Use something more specific, such as parent-child communication, avoid using the event bus.

posted this

Have an answer?


Please login first before posting an answer.