Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import JS to Vue from node_modules

Forgive my lack of expertise, but I am attempting to integrate and import This Grid System Into my own Vue Setup and Im having some slight trouble. Now, I normally import Plugins like so:

import VuePlugin from 'vue-plugin'

Vue.use(VuePlugin)

and I'm then able to use the components of said plugin globally, however this is not a plugin and I'm having trouble pulling in/importing the needed components into my own components... suggestions?

like image 244
John Durand Avatar asked Feb 26 '18 19:02

John Durand


People also ask

How do I connect node JS to Vue?

vue.config.js With this in place, all the calls start with /api will be redirected to http://localhost:3080 where the nodejs API running. Once this is configured, you can run the Vue app on port 8080 and nodejs API on 3080 still make them work together.

Can I use JavaScript in Vue?

A Vue application/web page is built of components that represent encapsulated elements of your interface. Components can be written in HTML, CSS, and JavaScript without dividing them into separate files.

How do I import Vue components?

STEP 01: First, Import the Child Component into the Parent Component inside script tag but above export default function declaration. STEP 02: Then, Register the Child Component inside the Parent Component by adding it to components object. STEP 03: Finally, Use the Child Component in the Parent Component Template.


1 Answers

If you use it via NPM:

First, install:

npm install --save vue-grid-layout

Then "register" it (probably a .vue - or .js - file):

import VueGridLayout from 'vue-grid-layout'

export default {
  ...
  components: {
    'GridLayout': VueGridLayout.GridLayout,
    'GridItem': VueGridLayout.GridItem
  }

If you use it via <script> tag:

Naturally, add it somewhere:

<script src="some-cdn-or-folder/vue-grid-layout.min.js"></script>

And "register" it (propably a .js file or another <script> tag):

var GridLayout = VueGridLayout.GridLayout;
var GridItem = VueGridLayout.GridItem;

new Vue({
    el: '#app',
    components: {
        "GridLayout": GridLayout,
        "GridItem": GridItem
    },

And... in your templates

In both cases, you can then use <grid-layout ...></grid-layout> in your template.

like image 151
acdcjunior Avatar answered Sep 17 '22 13:09

acdcjunior