Categories
Top Vue Packages

Top Vue Packages for Adding Drag and Drop Animation, and Debouncing

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at the best packages for adding drag and drop elements, animation, and debouncing.

Vue Slicksort

Vue Slicksort is an easy to use package that lets us create sortable lists in our Vue app in a snap.

To use it, we run:

npm i vue-slicksort

to install it.

Then we write:

<template>
  <div class="root">
    <SlickList lockAxis="y" v-model="items">
      <SlickItem v-for="(item, index) in items" :index="index" :key="index">{{ item }}</SlickItem>
    </SlickList>
  </div>
</template>

<script>
import { SlickList, SlickItem } from "vue-slicksort";

export default {
  components: {
    SlickItem,
    SlickList
  },
  data() {
    return {
      items: Array(20).fill().map((_, i)=> `item ${i}`)
    };
  }
};
</script>

to use it.

We use the SlickList item for creating the container.

Then we put SlickItem components inside it to display the sortable list.

Now we can drag and drop items on the list.

vue-dragula

vue-dragula is another easy to use drag and drop library for Vue apps.

To use it, we run:

npm i vue-dragula

Then we write:

main.js

import Vue from "vue";
import App from "./App.vue";
const VueDragula = require("vue-dragula");

Vue.use(VueDragula);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div class="root">
    <div class="container" v-dragula="colOne" bag="first-bag">
      <div v-for="text in colOne" :key="text">{{text}}</div>
    </div>
    <div class="container" v-dragula="colTwo" bag="first-bag">
      <div v-for="text in colTwo" :key="text">{{text}}</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      colOne: Array(15)
        .fill()
        .map((_, i) => `item ${i}`),
      colTwo: Array(15)
        .fill()
        .map((_, i) => `item ${i + 20}`)
    };
  }
};
</script>

We created 2 draggable lists with the v-dragula directive.

We set the bag prop to the same name so that we can drag and drop between them.

Inside each container, we render the elements that are draggable.

vue-dragscroll

vue-dragscroll is a directive that lets us enable scrolling by dragging our mouse.

To use it, we run:

npm i vue-dragscroll

to install it.

Then we write:

<template>
  <div class="root">
    <div v-dragscroll id="scroll">
      <div v-for="i in items" :key="i">{{i}}</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: Array(50)
        .fill()
        .map((_, i) => `item ${i}`)
    };
  }
};
</script>

<style>
#scroll {
  height: 300px;
  overflow-y: scroll;
}
</style>

to create a div that’s scrollable by clicking and holding our mouse and moving it.

We can use the x and y modifiers to only enable or disabling drag scrolling in one direction.

Also, we can disable drag scrolling for child elements.

Vue Animate CSS

Vue Animate CSS lets us add animation effects to our app without creating them from scratch ourselves.

We can install it by running:

npm i v-animate-css

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VAnimateCss from "v-animate-css";

Vue.use(VAnimateCss);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div class="root">
    <div v-animate-css="'fadeIn'">foo</div>
  </div>
</template>

<script>
export default {};
</script>

We add a fade-in animation effect by using the v-animate-css directive with the string 'fadeIn' .

There are many other effects we can add to our app with this library.

vue-debounce

We can use vue-debounce to delay a callback’s running.

To use it, we run:

npm i vue-debounce

to install it.

Then we write:

main.js

import Vue from "vue";
import App from "./App.vue";
import vueDebounce from "vue-debounce";

Vue.use(vueDebounce);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div class="root">
    <input v-debounce:300ms="log" type="text">
  </div>
</template>

<script>
export default {
  methods: {
    log(e){
      console.log(e)
    }
  }
};
</script>

We use the v-debounce directive with the 300ms modifier to delay the log method for 300 milliseconds before running it.

Then we can get the inputted value from it when we run it.

Conclusion

Vue Slicksort and vue-dragula let us add draggable elements to our app.

Vue Animate CSS is a library that lets us add CSS animation effects without writing them from scratch.

vue-debounce is a library for delaying callbacks.

Categories
Top Vue Packages

Top Vue Packages for Adding Autocomplete Input, Icons, Translations, and Highlight Words

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at the best packages for adding autocomplete input, translations, icons, and highlight words.

vuejs-auto-complete

vuejs-auto-complete is an easy to use autocomplete component for Vue apps.

To use it, we run:

npm i vuejs-auto-complete

to install it.

Then we write:

<template>
  <div>
    <autocomplete :source="source"></autocomplete>
  </div>
</template>

<script>
import Autocomplete from "vuejs-auto-complete";

export default {
  components: {
    Autocomplete
  },
  data() {
    return {
      source: [{ id: 1, name: "foo" }, { id: 2, name: "bar" }]
    };
  }
};
</script>

to use it.

We use the autocomplete to add the input.

We pass the data source for the autofill dropdown to the source prop.

We can also get data for the autofill directly from an API.

So we can write:

<template>
  <div>
    <autocomplete
      source="https://api.github.com/search/repositories?q="
      results-property="items"
      results-display="full_name"
    ></autocomplete>
  </div>
</template>

<script>
import Autocomplete from "vuejs-auto-complete";

export default {
  components: {
    Autocomplete
  }
};
</script>

to do that.

source is the URL without the value of the query string.

results-property is the property for the array of results.

results-display is the property we display to the user.

We can also set request headers for the API request with the request-headers prop.

The entries can be formatted if we pass a function into the results-display prop.

vue-feather-icon

vue-feather-icon is a package that has icons we can use.

To use it, we install it by running:

npm i vue-feather-icon

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueFeatherIcon from "vue-feather-icon";

Vue.use(VueFeatherIcon);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <activity-icon></activity-icon>
  </div>
</template>

<script>
import { Activity } from "vue-feather-icon";

export default {
  components: {
    ActivityIcon: Activity
  }
};
</script>

We register the plugin and we can use the icon from the package.

vue-highlight-words

We can use the vue-highlight-words package to add text highlighting.

To install it, we run:

npm i vue-highlight-words

Then we can use it by writing:

main.js

<template>
  <div id="app">
    <Highlighter
      class="my-highlight"
      :style="{ color: 'red' }"
      highlightClassName="highlight"
      :searchWords="keywords"
      :autoEscape="true"
      :textToHighlight="text"
    />
  </div>
</template>

<script>
import Highlighter from "vue-highlight-words";

export default {
  name: "app",
  components: {
    Highlighter
  },
  data() {
    return {
      text: "The quick brown fox jumps over the lazy dog",
      words: "and or the"
    };
  },
  computed: {
    keywords() {
      return this.words.split(" ");
    }
  }
};
</script>

We use the Highlighter component display the text with highlight.

textToHighlight has the text we want to apply highlighting to.

searchWords has an array of strings that we want to highlight in the textToHighlight text.

style is the style we set to the base text.

autoEscape escapes the text if it’s true .

vue-multilanguage

vue-multilanguage is a plugin we can use to display translations on the screen,

To use it, we run:

npm i vue-multilanguage

to install it.

Then we can write:

import Vue from "vue";
import App from "./App.vue";
import { MLInstaller, MLCreate, MLanguage } from "vue-multilanguage";

Vue.use(MLInstaller);

export default new MLCreate({
  initial: "english",
  languages: [
    new MLanguage("english").create({
      title: "hello {0}!",
      msg: "You have {d} dogs"
    }),

    new MLanguage("french").create({
      title: "bonjour {0}!",
      msg: "Vous avez 5 chiens"
    })
  ]
});
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div id="app">
    <p v-text="$ml.get('myMessage')"/>
  </div>
</template>

<script>
import { MLBuilder } from "vue-multilanguage";

export default {
  name: "app",
  data() {
    return { dogs: 5 };
  },
  computed: {
    mlmyMessage() {
      return new MLBuilder("msg").with("d", this.dogs);
    }
  }
};
</script>

We register the plugin.

Then we use the MLCreate constructor to populate the translations and set the initial language.

Then in our App component, we use the $ml.get method to get the translation.

The argument is the property without the ml prefix.

We use MLBuilder to get the translation and call with to interpolate the placeholders.

Conclusion

vuejs-auto-complete lets us add an autocomplete input to our app.

vue-feather-icon is a collection of icons we can use in our Vue app.

vue-highlight-words is a component that lets us highlight part of a piece of text.

vue-multilanguage lets us localize our app with translations.

Categories
Top Vue Packages

Top Vue Packages for Entering Text, File Uploading, and Rendering Trees

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at the best packages for adding draggable and resizable elements, file uploading, text editor, displaying tree structures, and input mask.

v-file-upload

We can use the v-file-upload package to add a file upload component to our Vue app.

To use it, we run:

npm i v-file-upload

to install it.

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";

import FileUpload from "v-file-upload";

Vue.use(FileUpload);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <file-upload :url="url" :thumb-url="thumbUrl" :headers="headers" @change="onFileChange"></file-upload>
</template>

<script>
import Vue from "vue";

export default {
  data() {
    return {
      url: "http://upload.url",
      headers: { "access-token": "<your-token>" },
      filesUploaded: []
    };
  },
  methods: {
    thumbUrl(file) {
      return file.thumnbnail;
    },
    onFileChange(file) {
      this.fileUploaded = file;
    }
  }
};
</script>

to use it.

We use the file-upload component.

We set the url prop to set the upload URL.

headers has the headers.

thumbUrl has the URL to the thumbnail.

Now we see a file selector on our screen.

vue-jstree

vue-jstree is a tree view for Vue apps.

To use it, we run:

npm i vue-jstree

to install it.

Then we write:

<template>
  <div>
    <v-jstree :data="data"></v-jstree>
  </div>
</template>

<script>
import VJstree from "vue-jstree";

export default {
  components: {
    VJstree
  },
  data() {
    return {
      data: [
        {
          text: "apple",
          children: [
            {
              text: "orange",
              selected: true
            },
            {
              text: "danger",
              icon: "fa fa-warning icon-state-danger"
            }
          ]
        },
        {
          text: "grape"
        }
      ]
    };
  }
};
</script>

to use it.

We use the v-jstree to include the tree view in our component.

The nodes are defined by arrays.

Each entry is an object with the text property for the text.

selected is an optional property to indicate selection.

icon os the class for the icon.

children is the class for the children.

We can change the icon class.

It takes a few props.

show-checkbox indicates whether to show a checkbox.

multiple lets us select multiple items.

collapse sets all tree nodes to the collapsed state.

loading-text is a loading function.

There are many more props it takes.

Vue-Trix Text Editor

Vue-Trix Text Editor is a rich text editor that we can use in our Vue app.,

To use it, we run:

npm i vue-trix

to install the package.

Then we write:

<template>
  <div>
    <VueTrix v-model="editorContent" placeholder="Enter content" localStorage/>
  </div>
</template>

<script>
import VueTrix from "vue-trix";

export default {
  components: {
    VueTrix
  },
  data(){
    return {
      editorContent: ''
    }
  }
};
</script>

to add the editor.

We add the VueTrix component to add it to our app.

We set a value for the placeholder to add a placeholder.

v-model binds the inputted value to the editorContent state.

localStorage save the inputted text to local storage.

vue-drag-resize

vue-drag-resize is an easy to use plugin to let us add draggable and resizable elements.

We install it by running:

npm i vue-drag-resize

Then we write:

<template>
  <div id="app">
    <VueDragResize isActive :w="200" :h="200" v-on:resizing="resize" v-on:dragging="resize">
      <p>{{ top }} х {{ left }}</p>
      <p>{{ width }} х {{ height }}</p>
    </VueDragResize>
  </div>
</template>

<script>
import VueDragResize from "vue-drag-resize";

export default {
  name: "app",

  components: {
    VueDragResize
  },

  data() {
    return {
      width: 0,
      height: 0,
      top: 0,
      left: 0
    };
  },

  methods: {
    resize(newRect) {
      this.width = newRect.width;
      this.height = newRect.height;
      this.top = newRect.top;
      this.left = newRect.left;
    }
  }
};
</script>

to use it.

We use the VueDraggable component to create a draggable and resizable component.

isActive sets the component to be active.

We set the initial height with the h prop.

The w prop is the initial width.

We listen to the resizing and dragging events to get the values of the new dimensions.

Conclusion

v-file-upload is a file upload component.

vue-jstree lets us display tree structures.

Vue-Trix Text Editor is a rich text editor for Vue apps.

vue-drag-resize lets us drag and resize elements.

Categories
Top Vue Packages

Top Vue Packages for Adding Wizards, Changing Title and Description, and More

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at the best packages for adding wizards, changing titles and meta attributes, using Moment, and adding percentage displays.

vue-good-wizard

vue-good-wizard is a wizard plugin for Vue apps.

To use it, we install it by writing:

npm i vue-good-wizard

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueGoodWizard from "vue-good-wizard";

Vue.use(VueGoodWizard);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <vue-good-wizard :steps="steps" :onNext="nextClicked" :onBack="backClicked">
      <div slot="page1">
        <h4>Step 1</h4>
        <p>This is step 1</p>
      </div>
      <div slot="page2">
        <h4>Step 2</h4>
        <p>This is step 2</p>
      </div>
      <div slot="page3">
        <h4>Review</h4>
        <p>review</p>
      </div>
    </vue-good-wizard>
  </div>
</template>

<script>
export default {
  name: "demo",
  data() {
    return {
      steps: [
        {
          label: "Step 1",
          slot: "page1"
        },
        {
          label: "Step 2",
          slot: "page2"
        },
        {
          label: "Review",
          slot: "page3",
          options: {
            nextDisabled: true
          }
        }
      ]
    };
  },
  methods: {
    nextClicked(currentPage) {
      console.log("next clicked", currentPage);
      return true;
    },
    backClicked(currentPage) {
      console.log("back clicked", currentPage);
      return true;
    }
  }
};
</script>

We use the vue-good-wizard component to create the wizard.

The steps prop has an array with the slot names and labels.

The slot property of each entry has the slots.

Then we populate the slots we defined by putting whatever we want in it.

options has options we can set on each step.

It also emits events and we can set listeners for them.

vue-headful

We can use the vue-headful package to set the title and meta description of our app.

We can install it by running:

npm i vue-headful

Then we write:

<template>
  <div>
    <vue-headful title="headful title" description="headful description"/>
  </div>
</template>

to use it.

vue-headful is the component to set the metadata.

title sets the title.

description sets the meta tag’s description attribute.

We can also set other attributes of the meta tag and the link tag.

vue-simple-calendar

vue-simple-calendar is a calendar component for Vue apps.

To use it, we run:

npm i vue-simple-calendar

to install the package.

Then we write:

<template>
  <div id="app">
    <calendar-view :show-date="showDate">
      <calendar-view-header
        slot="header"
        slot-scope="t"
        :header-props="t.headerProps"
        [@input](http://twitter.com/input "Twitter profile for @input")="setShowDate"
      />
    </calendar-view>
  </div>
</template>
<script>
import { CalendarView, CalendarViewHeader } from "vue-simple-calendar";
import "vue-simple-calendar/static/css/default.css";
import "vue-simple-calendar/static/css/holidays-us.css";

export default {
  name: "app",
  data() {
    return { showDate: new Date() };
  },
  components: {
    CalendarView,
    CalendarViewHeader
  },
  methods: {
    setShowDate(d) {
      this.showDate = d;
    }
  }
};
</script>

to use it.

We’ve to import the component and CSS files.

We then use the calendar-view for adding the calendar.

And we use the calendar-view-header component to add the header.

showDate sets the default date to show.

vue-easy-pie-chart

vue-easy-pie-chart lets us display a circular percentage display to our Vue app.

We install it by running:

npm i vue-easy-pie-chart

Then we write:

<template>
  <div>
    <vue-easy-pie-chart :percent="70"></vue-easy-pie-chart>
  </div>
</template>
<script>
import VueEasyPieChart from "vue-easy-pie-chart";
import "vue-easy-pie-chart/dist/vue-easy-pie-chart.css";

export default {
  components: { VueEasyPieChart }
};
</script>

to use it.

We set the percent to display the percentage.

Also, we’ve import the CSS to make it look correct.

vue-momentjs

vue-momentjs is a Vue plugin wrapper for moment.js.

We can install it by running:

npm install moment vue-momentjs

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import moment from "moment";
import VueMomentJS from "vue-momentjs";

Vue.use(VueMomentJS, moment);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>{{date}}</div>
</template>
<script>
export default {
  data() {
    return {
      date: this.$moment(new Date()).format("YYYY-MM-DD")
    };
  }
};
</script>

We use the this.$moment property to call the moment function.

Then we can call any other method of the moment object with it.

Conclusion

vue-good-wizard is a wizard component for Vue.

vue-headful lets us change the title and meta description for our Vue app.

vue-momentjs is a small wrapper for moment.

vue-easy-pie-chart is a percentage display.

Categories
Top Vue Packages

Top Vue Packages for Adding Printable Areas, Link Previews, and More

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at the best packages for adding printable areas, highlight text, link previews, handling keyboard shortcuts, and tag inputs.

vue-print-nb

vue-print-nb lets us define a printable area in our Vue app.

To install it, we run:

npm i vue-print-nb

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Print from "vue-print-nb";

Vue.use(Print);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div id="app">
    <div id="printMe">
      <p>foo</p>
      <p>bar</p>
      <p>baz</p>
    </div>

    <button v-print="'#printMe'">Print</button>
  </div>
</template>

<script>
export default {};
</script>

We use the v-print directive and pass the select of the printable element to it.

Then when we click on a button, then we’ll see a print dialog box with the preview of the printable area.

link-prevue

link-prevue provides us with a Vue component that shows us the preview of the page for the given URL.

We install it by running:

npm i link-prevue

Then we can use it by writing:

<template>
  <div id="app">
    <link-prevue url="https://example.com/"></link-prevue>
  </div>
</template>

<script>
import LinkPrevue from "link-prevue";

export default {
  components: {
    LinkPrevue
  }
};
</script>

We import the component and set the url attribute to set the attribute for the link.

It’s customizable.

For instance, we can set a custom loading indicator:

<template>
  <div id="app">
    <link-prevue url="https://example.com/">
      <template slot="loading">
        <h1>Loading...</h1>
      </template>
    </link-prevue>
  </div>
</template>

<script>
import LinkPrevue from "link-prevue";

export default {
  components: {
    LinkPrevue
  }
};
</script>

We populate the loading slot with our own content.

Then we display our loading indicator as it loads.

Other things we can customize include the card width, whether we show the button or not, and more.

v-hotkey

v-hotkey is a plugin that lets us handle keyboard shortcuts easier.

To install it, we run:

npm i v-hotkey

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueHotkey from "v-hotkey";

Vue.use(VueHotkey);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <span v-hotkey="keymap" v-show="display">Press 'ctrl + m' or hold 'enter'</span>
</template>

<script>
export default {
  data() {
    return {
      display: true
    };
  },
  methods: {
    toggle() {
      this.display = !this.display;
    },
    show() {
      this.display = true;
    },
    hide() {
      this.display = false;
    }
  },
  computed: {
    keymap() {
      return {
        "ctrl+m": this.toggle,
        enter: {
          keydown: this.hide,
          keyup: this.show
        }
      };
    }
  }
};
</script>

We have the keymap computed property that maps the key combinations to the method it calls.

Then we can use the v-hotkey directive to lets us use the key combos on the element.

vue-input-tag

vue-input-tag is a simple tags input for our Vue app.

To use it, we run:

npm i vue-input-tag

to install it.

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import InputTag from "vue-input-tag";
Vue.component("input-tag", InputTag);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <input-tag v-model="tags"></input-tag>
    <p>{{tags}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tags: []
    };
  }
};
</script>

We use the input-tag component to add the tags input.

Then we use v-model to bind the entered tags into an array of strings.

We can set various options like whether we want to allow duplicates, placeholders, max number of tags, and more.

vue-text-highlight

vue-text-highlight lets us highlight text in our Vue components.

To use it, we run:

npm i vue-text-highlight

to install it.

Then we use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import TextHighlight from "vue-text-highlight";

Vue.component("text-highlight", TextHighlight);
Vue.config.productionTip = false;

new Vue({
  render: h => h(App)
}).$mount("#app");

App.vue

<template>
  <div>
    <text-highlight :queries="queries">{{ description }}</text-highlight>
  </div>
</template>

<script>
export default {
  data() {
    return {
      queries: ["jump", "fox"],
      description: "The quick brown fox jumps over the lazy dog"
    };
  }
};
</script>

We use the text-highlight component with the queries prop to indicate what we want to highlight.

The value is an array of strings.

description is the text we want to highlight.

Conclusion

vue-print-nb lets us add a printable area to our Vue app.

link-prevue is a component for adding previews to links.

v-hotkey lets us handle keyboard combos.

vue-input-tag is a tag input component.

vue-text-highlight lets us highlight text.