javascript - Vue creating a plugin -


i feel bit i'm missing simple, i've been trying different stuff out , searching on place , can't figure out how use method custom plugin in vue application.

in 'vueplugin.js' have like:

const myplugin = {}; myplugin.install = function(vue, options){     vue.mymethod = function(){         console.log("it worked!");     } } 

in main.js have:

import myplugin './js/vueplugin.js' vue.use(myplugin); 

then in app.vue have:

export default {     name: 'app',     props: {},     data () {         return{ somedata: 'data' }     },     beforecreate: function(){         mymethod();     } } 

with error "mymethod not defined".

i've tried saying:

var foo = myplugin(); console.log(foo); 

in console object called "install" arguments: "exception: typeerror: 'caller' , 'arguments' restricted function properties , cannot accessed in context. @ function.remotefunction"

all of documentation seems show how create plugin , "use" it, not how access in it. missing here?

you have export object used in nodejs follows

file vueplugin.js

const myplugin = {} myplugin.install = function (vue, options) {   vue.mymethod = function () {     console.log('it worked!')   }   vue.prototype.mysecondmethod = function () {      console.log('my second method ')   } } export default myplugin 

while calling method cannot call method directly, have use following code shown

file app.vue

export default {     name: 'app',     props: {},     data () {         return{ somedata: 'data' }     },     beforecreate: function(){         vue.mymethod(); // call vue object , not directly  call mymethod()          this.mysecondmethod() // if used prototype based method creation in plugin      } } 

hopes


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -