[Vuejs]-Plugins in Vue's Single File Components

2👍

When your plugin is installed using Vue.use() it calls the install method of the plugin in which you are adding a method to the prototype of Vue

This allows you to access this method in any component using this.doStuff()

So you can access it in a mounted hook as

mounted() {
    this.doStuff();
}

I recommend that you name the property or method you are attaching on the prototype with a $ prefix.

So Vue.prototype.$doStuff can be accessed in any component as this.$doStuff. This is just a convention.

Leave a comment