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.

Categories
Top Vue Packages

Top Vue Packages for Infinite Scrolling, Displaying Toasts, and Add a Flexbox Grid

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 infinite scrolling, displaying toasts, and adding a flexbox grid.

vue-infinite-loading

We can add infinite scrolling to our app with the vue-infinite-loading package.

To add it, we run the following to install the package:

npm i vue-infinite-loading

Then we can use it by writing:

<template>
  <div>
    <div v-for="n in num" :key="n">{{n}}</div>
    <infinite-loading @infinite="infiniteHandler"></infinite-loading>
  </div>
</template>

<script>
import InfiniteLoading from "vue-infinite-loading";

export default {
  components: {
    InfiniteLoading
  },
  data() {
    return { num: 50 };
  },
  methods: {
    infiniteHandler($state) {
      this.num += 50;
      $state.loaded();
    }
  }
};
</script>

We add register and use the infinite-loading component to load more data.

It emits the infinite event which we listen to with the infiniteHandler .

It has a $state parameter, which we call loaded to indicate that we loaded what we want to display as we scroll.

We just loop through some numbers from 0 to num , which is updated by the infiniteHandler method.

If we don’t want to load more items, we can call $state.complete .

So we can write:

<template>
  <div>
    <div v-for="n in num" :key="n">{{n}}</div>
    <infinite-loading @infinite="infiniteHandler"></infinite-loading>
  </div>
</template>

<script>
import InfiniteLoading from "vue-infinite-loading";

export default {
  components: {
    InfiniteLoading
  },
  data() {
    return { num: 50 };
  },
  methods: {
    infiniteHandler($state) {
      if (this.num === 200) {
        $state.complete();
        return;
      }
      this.num += 50;
      $state.loaded();
    }
  }
};
</script>

Now we stop updating when this.num is 200.

This means there’s no more infinite scrolling with this.num is 200.

vue-grd

If we’re having trouble with flexbox, we can use vue-grd to make flexible work with our Vue app.

To install it, we run:

npm i vue-grd

Then we can write:

<template>
  <div>
    <vue-grid align="stretch" justify="start">
      <vue-cell width="fill">fill</vue-cell>
      <vue-cell width="5of12">5of12</vue-cell>
      <vue-cell width="3of12">3of12</vue-cell>
    </vue-grid>
  </div>
</template>

<script>
import { VueGrid, VueCell } from "vue-grd";

export default {
  components: {
    VueGrid,
    VueCell
  }
};
</script>

to create a flexbox container with vue-grid .

Then we have vue-cell to add the contents into the flexbox container.

The container has 12 columns, so we can change the width with strings like 5of12 or 3of12 to fill 5 of the 12 columns and 3 respectively.

fill fills the remaining space with the content in the vue-cell .

justify works the same way as the justify in CSS.

We can layout our time at the ends, with space in between, etc.

vue-material-checkbox

vue-material-checkbox lets us add a Material design style checkbox easily.

To install it, we write:

npm i vue-material-checkbox

Then we can use it by writing:

<template>
  <div>
    <Checkbox v-model="val" :value="42">My Checkbox</Checkbox>
    <p>{{val}}</p>
  </div>
</template>

<script>
import Checkbox from "vue-material-checkbox";

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

The Checkbox component binds to the val state.

It’s set to true if it’s checked and false otherwise.

We can set the color, disabled, required attribute, size, font size, and more options.

vue-toasted

We can display toasts with the vue-toasted plugin.

To install it, we run:

npm i vue-toasted

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Toasted from "vue-toasted";

Vue.use(Toasted);

Vue.config.productionTip = false;

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

App.vue

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

<script>
export default {
  mounted() {
    this.$toasted.show("hello");
  }
};
</script>

We register the plugin and then display a toast.

We can add actions to toasts.

For instance, we can write:

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

<script>
export default {
  mounted() {
    this.$toasted.show("hello", {
      action: [
        {
          text: "Cancel",
          onClick: (e, toastObject) => {
            toastObject.goAway(0);
          }
        },
        {
          text: "Undo",
          push: {
            name: "/",
            dontClose: true
          }
        }
      ]
    });
  }
};
</script>

We pass in an object that lets us add some links to the toast.

The first is a cancel button.

We call goAway to make it go away. The argument is the delay in milliseconds.

The 2nd one is one that lets us navigate to a route.

name has the route path from Vue Router.

Conclusion

vue-infinite-loading is an easy to use package to let us add infinite scrolling to our app.

vue-toasted lets us display toasts in our app.

vue-material-checkbox lets us display a checkbox.

vue-grd lets us create a flexbox grid without our own CSS.

Categories
Top Vue Packages

Top Vue Packages for Adding Timers, Social Sharing Links, Tooltips, and Callback Refs

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 timer, social sharing links, tooltips, and callback refs.

vue-timers

The vue-timers is a simple mixin that lets us add a timer like setTimeout and setInterval into our Vue app.

To use it, we first install it by writing:

npm i vue-timers

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueTimers from "vue-timers";

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

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

App.vue

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

<script>
export default {
  timers: {
    log: { time: 1000, autostart: true }
  },
  methods: {
    log() {
      console.log("Hello world");
    }
  }
};
</script>

We import the package and register it.

Then we use the this.$options.interval to store the object returned by setInterval .

The benefit of this package is that we can add reusable timers without adding our own code.

Clean up is also automatic.

We just add the timers object to call setTimeout .

autostart means that the timer is run automatically.

time is the delay in milliseconds.

We can also call it programmatically by writing:

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

<script>
export default {
  timers: {
    log: { time: 1000, autostart: true },
    foo: { time: 1000, autostart: false }
  },
  methods: {
    log() {
      console.log("Hello world");
    },
    foo() {
      console.log("foo");
    }
  },
  mounted() {
    this.$timer.start("foo");
  }
};
</script>

We added the foo timer that we can run ourselves with this.$timer.start .

vue-social-sharing

vue-social-sharing lets us add social sharing widgets into our code.

To install it, we run:

npm i vue-social-sharing

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueSocialSharing from "vue-social-sharing";

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

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

App.vue

<template>
  <div>
    <ShareNetwork
      network="facebook"
      url="https://example.com"
      title="hello"
      description="description"
      quote="quote"
      hashtags="vuejs,vite"
    >Share on Facebook</ShareNetwork>
  </div>
</template>

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

We share the https://example.com link to Facebook with the given title and description.

We can also add a quote.

We set the network to facebook to share the link to Facebook.

It supports many other social networks like Twitter, Instagram, and more.

vue-popperjs

vue-popperjs lets us add tooltips easily into our app.

To install it, we run:

npm i vue-popperjs

Then we can use it by writing:

<template>
  <div>
    <popper
      trigger="clickToOpen"
      :options="{
      placement: 'top',
      modifiers: { offset: { offset: '0,10px' } }
    }"
    >
      <div class="popper">content</div>

      <button slot="reference">click me</button>
    </popper>
  </div>
</template>

<script>
import Popper from "vue-popperjs";
import "vue-popperjs/dist/vue-popper.css";

export default {
  components: {
    popper: Popper
  }
};
</script>

We use the bundled popper component.

The trigger prop lets us set how to open the tooltip.

clickToOpen means it’ll open on click.

The reference slot has the element that’s used to open the tooltip.

The default slot has the content.

We also import the CSS.

We can also set the offset to what we want.

placement lets us set the placement of the tooltip.

vue-ref

vue-ref lets us use a direct to set a ref with a callback.

To install it, we run:

npm i vue-ref

Then we use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import ref from "vue-ref";
Vue.use(ref);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <input v-ref="c => this.dom = c">
  </div>
</template>

<script>
export default {
  data() {
    return {
      dom: undefined
    };
  },
  mounted() {
    this.dom.focus();
  }
};
</script>

We use the v-ref directive to get the element and set it as the value of this.dom .

Then we can call focus on the input to focus it.

Conclusion

The vue-timers package lets us add timers to our components easier than using setTimeout and setInterval .

vue-social-sharing lets us ad social sharing links.

vue-popperjs lets us add tooltips with flexible styling.

vue-ref lets us add callback refs.