10

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?

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, that did it. however i was wondering, is there anyway to make the component definition cleaner by doing something like import VueGridLayout.GridLayout as GridLayout from 'vue-grid-layout' and then defining it in my components as just components: { GridLayout, ... }
I don't think so, because I'm assuming the VueGridLayout is the default import, and you can't destructure those. You could declare a const GridLayout = VueGridLayout.GridLayout, but I believe that's what you are trying to run away from...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.