javascript - Include global functions in Vue.js -
in vue.js application want have global functions. example callapi()
function can call every time need access data.
what best way include these functions can access in components?
- should create file functions.js , include in main.js?
- should create mixin , include in main.js?
- is there better option?
your best bet plugin, lets add features global vue system.
[from vuejs docs]
myplugin.install = function (vue, options) { // 1. add global method or property vue.myglobalmethod = ... // 2. add global asset vue.directive('my-directive', {}) // 3. add instance method vue.prototype.$mymethod = ... }
then add
vue.use(myplugin)
in code before calling function.
vue.myglobalmethod(parameters);
or in case
vue.callapi(parameters);
Comments
Post a Comment