Skip to content
Advertisement

how use npm packages with Vue SPA

i have created Vuejs app using vue-loader,now i need to use an installed npm package as follow :

   var x = require('package-name')
   Vue.use(x)

but i have this error :

Uncaught TypeError: plugin.apply is not a function

dose Vuejs require a special type packages or it can work with any JavaScript package and this error can be solved

Advertisement

Answer

Plugins are specific Vue packages that add global-level functionality to Vue, so if you aren’t using a Vue plugin then you don’t need to register it with Vue using Vue.use().

In general there isn’t any issue using non-vue-specific packages via npm but if you need to register something globally, you can usually get away with simply attaching it to window like so:

window.x = require('package-name');
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement