Categories
Top Vue Packages

Top Vue Packages for Charts and Useful Filters and Directives

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 how the best packages for adding charts, filters, and more.

vue-chartjs

vue-chartjs is a great package for adding us add all kinds of chats.

To install it, we run:

npm i vue-chartjs chart.js

We can then use it by writing:

Chart.vue

<script>
import { Bar } from "vue-chartjs";

export default {
  extends: Bar,
  mounted() {
    this.renderChart({
      labels: [
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
      ],
      datasets: [
        {
          label: "Votes",
          backgroundColor: "green",
          data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
        }
      ]
    });
  }
};
</script>

App.vue

<template>
  <div>
    <Chart/>
  </div>
</template>

<script>
import Chart from "@/components/Chart";

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

Our chart is in Chart.vue . There’s no template in the component. We just import the Bar component so that we can create a bar chart with our own data. datasets has the data that we want to display on the bars. labels has the chart labels at the bottom. this.renderChart renders the chart. In App.vue , we add the Chart component to display the chart. Alternatively, we can pass in props to our chart:

Chart.vue

<script>
import { Bar } from "vue-chartjs";

export default {
  extends: Bar,
  props: ["data", "options"],
  mounted() {
    this.renderChart(this.data, this.options);
  }
};
</script>

App.vue

<template>
  <div>
    <Chart :data="data"/>
  </div>
</template>

<script>
import Chart from "@/components/Chart";

export default {
  components: {
    Chart
  },
  data() {
    return {
      data: {
        labels: [
          "January",
          "February",
          "March",
          "April",
          "May",
          "June",
          "July",
          "August",
          "September",
          "October",
          "November",
          "December"
        ],
        datasets: [
          {
            label: "Votes",
            backgroundColor: "green",
            data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
          }
        ]
      }
    };
  }
};
</script>

This is more flexible since our data comes from external sources like an API. We pass in the props for the data. It supports many other kinds of charts like line charts, pie charts, etc.

VueMorphling

The VueMorphling package has a collection of filters and directives that we can use to do various things.

To install it, we can run:

npm i vue-morphling

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import { VueMorphling } from "vue-morphling";

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

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

App.vue

<template>
  <div>
    <p>{{ new Date(1990,2,20) | morph-age }}</p>
  </div>
</template>

<script>
export default {
  data() {}
};
</script>

We used the morph-age filter to display the age of the person given the date. We can use the morph-chop filter to cut off a part of a string.

For instance, we can write:

<template>
  <div>
    <p>{{ 'foo bar' | morph-chop(2) }}</p>
  </div>
</template>

<script>
export default {
  data() {}
};
</script>

We remove the last 2 characters of a string with morph-chop(2) . We can pass in 'start' to remove the first number of characters. And we can pass in 'end' to remove the last number of characters. Filters can also be used to templates, so we can write:

const msg **=** this.$morphChop('foo bar', 2);

To do the same thing we did in our template in our component code. It also has many other filters, including ones for currencies, dates, and more.

We can display JSON with the morph-json filter:

<template>
  <div>
    <pre>{{ obj | morph-json(2) }}</pre>
  </div>
</template>

<script>
export default {
  data() {
    return {
      obj: {
        foo: { bar: 3 }
      }
    };
  }
};
</script>

2 means we have 2 spaces for indentation. It has to be used with the pre tag so we get the code formatting. It also comes with a few useful directives. We can use the v-morph-highlight directive to add highlighting to our text.

For instance, we can write:

<template>
  <div>
    <p v-morph-highlight="'dog::green'">Dogs are great. I love dogs.</p>
  </div>
</template>

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

We highlight the word ‘dog’ no matter what case it starts with.

Conclusion

We can add charts to a Vue app with vue-chartjs. To display things our way, we can save some time with the vue-morphling package, which comes with various filters and directives. Thanks for reading my article, I hope you found it helpful!

Categories
Top Vue Packages

Top Vue Packages for Adding a Time Selector, Context Menu, and Scrollbar

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 how the best packages for adding a time selector, context menu, and more.

Vue-timeselector

vue-timeselector lets us add a time picker into our Vue app.

To install it, we can run:

npm i vue-timeselector

Then we can use it by writing:

App.vue

<template>
  <div>
    <timeselector v-model="time"></timeselector>
    <p>{{time}}</p>
  </div>
</template>

<script>
import Timeselector from "vue-timeselector";

export default {
  components: {
    Timeselector
  },
  data() {
    return {
      time: undefined
    };
  }
};
</script>

Now we get an input element where we can set the time. It emits the input event which is emitted with the inputted value. name sets the name attribute of the input. We can also set the input to required or disable the input. Also, we can set a placeholder like any other input. Optionally, we can add a second picker to let us pick the seconds. The interval can be changed with the interval prop.

We can add the second’s picker and change the interval of the pickers by writing:

<template>
  <div>
    <timeselector v-model="time" :interval="{h:2, m:1, s:10}" displaySeconds></timeselector>
    <p>{{time}}</p>
  </div>
</template>

<script>
import Timeselector from "vue-timeselector";

export default {
  components: {
    Timeselector
  },
  data() {
    return {
      time: undefined
    };
  }
};
</script>

vue-simple-context-menu

The vue-simple-context-menu lets us add a context menu to our app.

To install it, we can run:

npm i vue-simple-context-menu

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import "vue-simple-context-menu/dist/vue-simple-context-menu.css";

import VueSimpleContextMenu from "vue-simple-context-menu";
Vue.component("vue-simple-context-menu", VueSimpleContextMenu);

Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <div class="item-wrapper">
      <div
        v-for="item in items"
        :key="item"
        [@click](http://twitter.com/click "Twitter profile for @click").prevent.stop="handleClick($event, item)"
      >{{item}}</div>
    </div>

<vue-simple-context-menu
      :elementId="'myUniqueId'"
      :options="options"
      :ref="'vueSimpleContextMenu'"
      [@option](http://twitter.com/option "Twitter profile for @option")-clicked="optionClicked"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: ["foo", "bar"],
      options: [
        {
          name: "foo"
        },
        {
          name: "bar"
        }
      ]
    };
  },
  methods: {
    handleClick(event, item) {
      this.$refs.vueSimpleContextMenu.showMenu(event, item);
    },

    optionClicked(event) {
      window.alert(JSON.stringify(event));
    }
  }
};
</script>

We register the plugin and import the CSS for the menu from the package in main.js . Then we add the vue-simple-context-menu to add the menu to our component. It can be styled with the vue-simple-context-menu class.

vue2-perfect-scrollbar

The vue2-perfect-scrollbar package lets us add a scrollbar to our app into any element.

We can install it by running:

npm i vue2-perfect-scrollbar

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import PerfectScrollbar from "vue2-perfect-scrollbar";
import "vue2-perfect-scrollbar/dist/vue2-perfect-scrollbar.css";

Vue.use(PerfectScrollbar);

Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <perfect-scrollbar>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ultricies, odio vitae cursus placerat, felis nibh consectetur arcu, vel consectetur enim enim in purus. Cras non viverra arcu, ac semper mi. Sed vehicula porttitor malesuada. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas id libero eleifend, bibendum odio a, efficitur neque. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum hendrerit tellus posuere massa rutrum, eu congue nisi ornare.</p>

      <p>Vestibulum sed dapibus eros. Quisque semper quam non laoreet rutrum. Vestibulum efficitur dictum sem eget ornare. Nullam egestas arcu erat, quis elementum felis venenatis ac. In commodo, lacus at vestibulum viverra, ante ante tristique metus, id tempus augue erat sed ipsum. Nullam ut nibh non augue mattis porta. Curabitur consectetur tellus eu tellus eleifend, ut ornare urna suscipit. Ut pharetra nulla fringilla, ultrices arcu ac, ullamcorper leo. In ultricies erat ac semper laoreet. Ut tristique condimentum dui eget tempus. Sed sed placerat nulla. Ut at blandit neque, vitae sodales urna. Vestibulum id ultrices ante, eget blandit ex.</p>
    </perfect-scrollbar>
  </div>
</template>

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

<style>
.ps {
  height: 400px;
}
</style>

Because we have the perfect-scrollbar component, we’ll see a scrollbar generated by it displayed instead of the browser’s native scrollbar.

We can style the element rendered by perfect-scrollbar with the .ps class.

Conclusion

vue-timeselector lets us add a time picker to our Vue app. vue-simple-context-menu lets us add a context menu to our app. vue2-perfect-scrollbar replaces the native scrollbar with its own. Thanks for reading my article, I hope you found it helpful!

Categories
Top Vue Packages

Top Vue Packages for Adding Text Editor, Spinner, Progress Bar, and File Upload

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 how the best packages for adding a rich text editor, file upload control, spinner, and progress bar.

Vue2Editor

Vue2Editor is an easy to use rich text editor component based on Quill.

To install it, we can run:

npm i vue2-editor

Then we can use it by writing:

<template>
  <div id="app">
    <vue-editor v-model="content"></vue-editor>
    <p v-html="content"></p>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";

export default {
  components: {
    VueEditor
  },

  data() {
    return {
      content: "<h1>hello</h1>"
    };
  }
};
</script>

We have the vue-editor component which binds to the content state with v-model .

It comes with common features like bold, italic, underline, different style text, lists, images, videos, links, and more.

There are many other customizations like placeholders.

It also emits events for blur, focus, adding images, changing selection, and more.

We can also change how images are uploaded.

vue-spinner

vue-spinner is a spinner component so that we display something when our data is loading.

To use it, we first install it by running:

npm i vue-spinner

Then we can use it by writing:

<template>
  <div id="app">
    <pulse-loader loading :color="color"></pulse-loader>
  </div>
</template>

<script>
import PulseLoader from "vue-spinner/src/PulseLoader.vue";

export default {
  components: {
    PulseLoader
  },
  data() {
    return {
      color: "green"
    };
  }
};
</script>

We set the loading prop to indicate that it’s loading.

color sets the color.

It comes with many other styles like grid-loader , clip-loader , and much more.

vue2-dropzone

vue2-dropzone is a dropzone component that we can use to add a file upload input to our Vue app.

To use it, we run:

npm i vue2-dropzone

Then we can use it by writing:

<template>
  <div id="app">
    <vue-dropzone ref="dropzone" id="dropzone" :options="dropzoneOptions"></vue-dropzone>
  </div>
</template>

<script>
import vue2Dropzone from "vue2-dropzone";
import "vue2-dropzone/dist/vue2Dropzone.min.css";
export default {
  name: "app",
  components: {
    vueDropzone: vue2Dropzone
  },
  data() {
    return {
      dropzoneOptions: {
        url: "https://example.com",
        thumbnailWidth: 150,
        maxFilesize: 0.5,
        headers: { "Header": "header value" }
      }
    };
  }
};
</script>

We use the vue-dropzone component with some options.

url is the URL to upload to.

thumbnailwidth is the width of the thumbnail.

maxFilesize is the maximum file size of the file selected,.

headers is the headers we send with the request.

vue-count-to

vue-count-to is a component that lets us add animation to count up or down to a specific number.

To install it, we run:

npm i vue-count-to

Then we can use it by writing:

<template>
  <countTo :startVal="startVal" :endVal="endVal" :duration="3000"></countTo>
</template>

<script>
import countTo from "vue-count-to";
export default {
  components: { countTo },
  data() {
    return {
      startVal: 0,
      endVal: 2020
    };
  }
};
</script>

We just set the startVal prop to set the starting value of the animation.

endVal sets the end value of the animation.

duration is the animation duration.

vue-progressbar

vue-progressbar is a progress bar component.

To use it, first we install it by running:

npm i vue-progressbar

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueProgressBar from "vue-progressbar";

const options = {
  color: "green",
  failedColor: "red",
  thickness: "5px",
  transition: {
    speed: "1.2s",
    opacity: "1.6s",
    termination: 300
  },
  autoRevert: true,
  location: "top",
  inverse: false
};

Vue.use(VueProgressBar, options);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div id="app">
    <vue-progress-bar></vue-progress-bar>
  </div>
</template>

<script>
export default {
  mounted() {
    this.$Progress.finish();
  },
  created() {
    this.$Progress.start();
  }
};
</script>

We have the options object with the options that we set for the progress bar.

color is the bar color.

failedColor is the color when loading fails.

thickness is the thickness of the bar.

transition is the speed of the animation.

opacity is the opacity of the bar.

termination is when it terminates.

autoRevert means that it reverses automatically when loading fails.

location is the location of the bar.

inverse is inverting the direction.

Conclusion

Vue2Editor is the rich text editor.

vue2-dropzone is a file upload widget.

vue-count-to provides us with a way to animate number displays.

vue-progressbar lets us display a progress bar.

vue-spinner is a spinner we can add.

Categories
Top Vue Packages

Top Vue Packages for Adding Croppers, Calendars, and Lodash

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 how the best packages to add a cropper, calendar, full-year date picker, and Lodash.

vue-cropperjs

We can use the vue-cropperjs package to add an image cropper to our Vue app.

To use it, first we install it by running:

npm i vue-cropperjs

Then we can use it by writing:

<template>
  <div>
    <vue-cropper ref="cropper" src="https://placekitten.com/200/200" alt="Source Image"></vue-cropper>
  </div>
</template>

<script>
import VueCropper from "vue-cropperjs";
import "cropperjs/dist/cropper.css";

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

We just have to import and register the VueCropper component.

Then we set the image with the src prop.

It emits the ready , cropstart , cropmove , cropend , crop , and zoom events.

So we can do anything we want.

Also, we can use it programmatically by calling methods from the ref.

For instance, we can write:

this.$refs.cropper.zoom(1.5);

to zoom in.

vue-lodash

vue-lodash is a wrapper for Lodash that we can use in our Vue apps.

To install it, we run:

npm i vue-lodash lodash

Lodash is a required dependency.

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueLodash from "vue-lodash";
import lodash from "lodash";

Vue.use(VueLodash, { name: "custom", lodash });
Vue.config.productionTip = false;

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

We registered the VueLodash plugin. The name is the property name that we can invoke Lodash with.

lodash is the library itself.

Then in our component, we can write:

<template>
  <div></div>
</template>

<script>
export default {
  mounted() {
    console.log(this.lodash.random(20));
    console.log(this._.random(20));
    console.log(this.custom.random(20));
  }
};
</script>

We can invoke Lodash with the lodash , _ , or custom property as we defined in the name property of the object we passed into Vue.use .

vue-material-year-calendar

vue-material-year-calendar is a useful package for letting us add a full year calendar.

It displays all months on the screen instead of one like most date pickers.

To install it, we run:

npm i vue-material-year-calendar

Then we can use it by writing:

<template>
  <YearCalendar
    v-model="year"
    :activeDates.sync="activeDates"
    [@toggleDate](http://twitter.com/toggleDate "Twitter profile for @toggleDate")="toggleDate"
    prefixClass="prefix"
    :activeClass="activeClass"
  ></YearCalendar>
</template>

<script>
import YearCalendar from "vue-material-year-calendar";

export default {
  components: { YearCalendar },
  data() {
    return {
      year: 2020,
      activeDates: [
        { date: "2020-02-13" },
        { date: "2020-02-14", className: "red" },
        { date: "2020-02-15", className: "blue" },
        { date: "2020-02-16" }
      ],
      activeClass: "active"
    };
  },
  methods: {
    toggleDate(dateInfo) {
      console.log(dateInfo);
    }
  }
};
</script>

<style>
.red {
  color: red;
}

.blue {
  color: blue;
}

.active {
  background: yellow;
}
</style>

We use the YearCalendar component.

The toggleDate event is set to the toggleDate method to log the date.

prefixClass lets us add a prefix to the wrapper class.

activeDates has sets the days to be highlighted. We make the highlight with our own class.

v-model binds to year to set the initial year.

vue-full-calendar

vue-full-calendar is a calendar widget that we can add to a Vue app.

To install it, we run:

npm i vue-full-calendar moment jquery

Moment and jQuery are a required dependencies

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import FullCalendar from "vue-full-calendar";
import "fullcalendar/dist/fullcalendar.css";

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

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

We register the plugin and import the CSS.

App.vue

<template>
  <full-calendar :events="events"></full-calendar>
</template>

<script>
import { FullCalendar } from "vue-full-calendar";
export default {
  components: {
    FullCalendar
  },
  data() {
    return {
      events: [
        {
          title: "eat",
          start: "2020-01-01"
        },
        {
          title: "drink",
          start: "2020-01-05",
          end: "2020-01-07"
        },
        {
          title: "sleep",
          start: "2020-01-09T12:30:00",
          allDay: false
        }
      ]
    };
  }
};
</script>

We use the full-calendar component.

We pass in an array of events with the title, start, and end dates in each entry.

Also, we can set the allDay property to add a full-day event.

Conclusion

vue-cropperjs lets us add an image cropped to our Vue app.

The vue-full-calendar package is a calendar widget we can use to display events

The vue-material-year-calendar is a unique date picker in that it displays the whole year.

vue-lodash is a Vue wrapper for Lodash.

Categories
Top Vue Packages

Top Vue Packages for Adding Code Editors, Notifications, and Watch Element Resizing

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 how the best packages for adding code editors, notifications, and watching element resizing.

vue-codemirror

vue-codemirror provides us with a box to display code.

To use it, we install it by running:

npm i vue-codemirror

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueCodemirror from "vue-codemirror";
import "codemirror/lib/codemirror.css";

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

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

App.vue

<template>
  <div>
    <codemirror v-model="code" :options="cmOptions"></codemirror>
  </div>
</template>

<script>
import "codemirror/mode/javascript/javascript.js";
import "codemirror/theme/base16-dark.css";

export default {
  data() {
    return {
      code: "const a = 1",
      cmOptions: {
        tabSize: 4,
        mode: "text/javascript",
        theme: "base16-dark",
        lineNumbers: true,
        line: true
      }
    };
  },
  methods: {
    onCmReady(cm) {
      console.log("the editor is readied!", cm);
    },
    onCmFocus(cm) {
      console.log("the editor is focus!", cm);
    },
    onCmCodeChange(newCode) {
      console.log("this is new code", newCode);
      this.code = newCode;
    }
  }
};
</script>

We have the codemirror component.

The code is bound with v-model to code .

We can also add some options like tabSize for size of tabs.

mode for the language we’re displaying.

theme for the display theme.

lineNumber to indicate whether we show line numbers.

It also comes with a merge mode, which lets us compare code side by side.

To use that, we can write:

<template>
  <div>
    <codemirror merge :options="cmOption" @scroll="onCmScroll"></codemirror>
  </div>
</template>

<script>
import "codemirror/addon/merge/merge.js";
import "codemirror/addon/merge/merge.css";
import DiffMatchPatch from "diff-match-patch";
window.diff_match_patch = DiffMatchPatch;
window.DIFF_DELETE = -1;
window.DIFF_INSERT = 1;
window.DIFF_EQUAL = 0;
export default {
  data() {
    return {
      cmOption: {
        value: "<p>james</p>",
        origLeft: null,
        orig: "<p>james smith</p>",
        connect: "align",
        mode: "text/html",
        lineNumbers: true,
        collapseIdentical: false,
        highlightDifferences: true
      }
    };
  },
  methods: {
    onCmScroll() {
      console.log("onCmScroll");
    }
  }
};
</script>

value has the new code.

orig has the original code.

collapseIdentical lets us collapse identical code by default.

highlightDifference lets us highlight any code differences between the original and the current code.

vue-notification

vue-notification is a library that lets us display notifications.

To install it, we run:

npm i vue-notification

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Notifications from "vue-notification";

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

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

App.vue

<template>
  <div>
    <notifications group="foo"/>
  </div>
</template>

<script>
export default {
  mounted() {
    this.$notify({
      group: "foo",
      title: "title",
      text: "Hello"
    });
  }
};
</script>

We add the notification component with the group prop.

Then we use the same group value when we call this.$notify to display notifications.

title is the title and text is the content.

We can style it with the generated classes.

We can also create custom notification by populating the slots that it comes with:

<template>
  <div>
    <notifications group="foo" position="top left">
      <template slot="body" slot-scope="props">
        <div>
          <a class="title">{{props.item.title}}</a>
          <a class="close" @click="props.close">close</a>
          <div v-html="props.item.text"></div>
        </div>
      </template>
    </notifications>
  </div>
</template>

<script>
export default {
  mounted() {
    this.$notify({
      group: "foo",
      title: "title",
      text: "Hello"
    });
  }
};
</script>

We populated the body slot with our own content.

It comes with a props.close to close the notification.

The width and velocity can be changed.

vue-resize

vue-resize lets us watch for elements being resized.

To install it, we run:

npm i vue-resize

Then we can use it by using:

main.js

import Vue from "vue";
import App from "./App.vue";
import { ResizeObserver } from "vue-resize";

Vue.component("resize-observer", ResizeObserver);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <resize-observer @notify="handleResize"/>
  </div>
</template>

<script>
export default {
  methods: {
    handleResize({ width, height }) {
      console.log(width, height);
    }
  }
};
</script>

 <style scoped>
div {
  position: relative;
  width: 100vw;
}
</style>

We listen to elements being resized with the resize-observer component.

Conclusion

vue-codemirror lets us add a code editor that supports diffing.

vue-notification lets us add notifications of any variety.

vue-resize lets us watch for elements being resized.