user2950593
user2950593

Reputation: 9617

using npm module without webpack but with inline script vue.js

I am not using webpack, I include vue as external script Something like this:

<script src ="unpckg.com/vue.js-latest"></script>

And I want to use npm module

https://www.npmjs.com/package/vue-context-menu

So I include it like this:

<script src= "https://unpkg.com/[email protected]/vue-context-menu.js"></script>

So how do I use it? Normally I would right:

import contextMenu from 'vue-context-menu'

But it gives me an error now.

Upvotes: 0

Views: 187

Answers (1)

Harshal Patil
Harshal Patil

Reputation: 20960

It should be simple:

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src= "https://unpkg.com/[email protected]/vue-context-menu.js"></script>

 <script>
      // This is important
      Vue.component('own-context-menu', window.VueContextMenu);
 </script>

vue-context-menu registers the component on window object as:

window.VueContextMenu = VueContextMenu

Please let me know if it does not help.

Upvotes: 1

Related Questions