Good afternoon, I'm a beginner in both javascript and vue, and I'm having some difficulty creating a global function in vue. Could someone give me an example? Grate
Good afternoon, I'm a beginner in both javascript and vue, and I'm having some difficulty creating a global function in vue. Could someone give me an example? Grate
To add a global method to Vue you can create a plugin:
According to Vue.js - Plugins :
MeuPlugin.install = function (Vue, options) {
// 1. Adiciona o método global ou propriedade
Vue.meuMetodoGlobal = ...
// 2. Adiciona uma diretiva global
Vue.directive('minha-diretiva', {})
// 3. Adiciona um método de instância
Vue.prototype.$meuMetodo = ...
}
Then you add the plugin to Vue:
Vue.use(MeuPlugin)
In your code, to call the method.
Vue.meuMetodoGlobal(parametros);
Reference: Include global functions in Vue.js