P
P
pegas2018-12-11 02:28:54
JavaScript
pegas, 2018-12-11 02:28:54

How to call a global method created as a plugin?

let MyPlugin = {};

MyPlugin.install = function (Vue) {
    Vue.myGlobalMethod = function () {
        alert(999)
    }
};

Vue.use(MyPlugin);

I have declared a global method myGlobalMethod how can I call it?
If the template has {{ myGlobalMethod() }} then the error is

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-12-11
@1PeGaS

To be able to call like this, the method must be placed in the prototype: Vue.prototype.myGlobalMethod = ....

A
Alexander Taratin, 2018-12-11
@Taraflex

Looks like you need Global Mixins
https://ru.vuejs.org/v2/guide/mixins.html#%D0%93%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question