Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Vue.Draggable CDN without webpack?

I’m a newbie on Vue. One of the pages (salesview) on my client’s CodeIgniter website needs to use Vue so I included it by

<script src="https://cdn.jsdelivr.net/npm/vue"></script>

and I declared Vue and its components in a file called salesview.js. Now, I need to use the Vue.Draggable component. I added it to the page like so:

<script src="//cdn.jsdelivr.net/npm/[email protected]/Sortable.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.20.0/vuedraggable.umd.min.js"></script>

Since I’m not using webpack, how can I use this component?

like image 447
Esthon Wood Avatar asked May 04 '20 06:05

Esthon Wood


People also ask

Is webpack necessary for Vue?

js files using Webpack (see below). However, you can also create Vue components in *. js files, the template that the component uses is then defined in a different file or given as a simple string. In that case, you do not need Webpack.

Does Vue create use webpack?

Vue CLI is built on top of Webpack and so for beginners, you do not need to know what Webpack is as the Vue CLI has taken care of the configurations with great default presets and you literally need 0 configs to start.

What is VUE draggable?

"Vue Draggable is a Vue component allowing drag-and-drop and synchronization with view model array. It's available in versions for Vue 1. x, 2. x and 3. x, and is based on and offering all features of Sortable.


1 Answers

I solved my problem by accessing vuedraggable from the window object and added it to the components options, like so:

var vm = new Vue({
    el: '#app',
  components: {
    'sv-lead-column': svLeadColumn,
    'sv-customer-column': svCustomerColumn,
    draggable: window['vuedraggable']
  },
  ...
})
like image 99
Esthon Wood Avatar answered Sep 24 '22 00:09

Esthon Wood