Categories
Top Vue Packages

Top Vue Packages for Handling Outside Clicks and Add Tabs and Date Pickers

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 handling outside clicks, tabs, and date pickers.

v-click-outside-x

v-click-outside-x is a directive that lets us handle clicks outside an element easily.

To install it, we run:

npm i v-click-outside-x

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import * as vClickOutside from "v-click-outside-x";

Vue.use(vClickOutside);

Vue.config.productionTip = false;

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

App.vue

<template>
  <div v-click-outside="onClickOutside">click me</div>
</template>

<script>
export default {
  methods: {
    onClickOutside(event) {
      console.log("Clicked outside. Event: ", event);
    }
  }
};
</script>

We have a div that we add the v-click-outside directive to.

And we pass an event handler function to it for handling clicks outside the element.

event is the event object that we use when clicking outside.

We can also use it to handle multiple events.

For instance, we can write:

<template>
  <div
    v-click-outside.capture="onClickOutside"
    v-click-outside:click="onClickOutside"
    v-click-outside:pointerdown.capture="onClickOutside"
  >click me</div>
</template>

<script>
export default {
  methods: {
    onClickOutside(event) {
      console.log("Clicked outside. Event: ", event);
    }
  }
};
</script>

vue-tmn-tabs

vue-tmn-tabs is a simple tabs component.

To install it, we can run:

npm i vue-tmn-tabs

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import { Tab, Tabs } from "vue-tmn-tabs";

Vue.component("tab", Tab);
Vue.component("tabs", Tabs);

Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <tabs transitionName="fade">
      <tab :title="'Tab1'">
        <h1>Tab 1</h1>
        <p>foo</p>
      </tab>
      <tab :title="'Tab2'">
        <h1>Tab 2</h1>
        <p>bar</p>
      </tab>
      <tab :title="'Tab3'">
        <h1>Tab 3</h1>
        <p>baz</p>
      </tab>
      <tab :title="'Tab4'">
        <h1>Tab 4</h1>
        <p>qu</p>
      </tab>
    </tabs>
  </div>
</template>

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

We have the tabs component to add the tabs.

title is the title for the tabs, which are displayed in the tab buttons.

tab has the tab content.

We can add styling to the generated classes.

vue2-datepicker

vue2-datepicker is a date picker that is very customizable.

To use it, we install it by running:

npm i vue2-datepicker

Then we can use it by writing:

<template>
  <div>
    <date-picker v-model="time" valuetype="format"></date-picker>
    <p>{{time}}</p>
  </div>
</template>

<script>
import DatePicker from "vue2-datepicker";
import "vue2-datepicker/index.css";

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

We import the component and CSS.

Then we use the date-picker component to display the items.

v-model is bound to the time state.

valuetype specifies the format of the selected value.

The possible values include date , timestamp , format , and token .

So we can also write:

<template>
  <div>
    <date-picker v-model="time" type="datetime"></date-picker>
    <p>{{time}}</p>
  </div>
</template>

<script>
import DatePicker from "vue2-datepicker";
import "vue2-datepicker/index.css";

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

to add a time picker.

Or we can write:

<template>
  <div>
    <date-picker v-model="time" range></date-picker>
    <p>{{time}}</p>
  </div>
</template>

<script>
import DatePicker from "vue2-datepicker";
import "vue2-datepicker/index.css";

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

to let us select a start and end date with one date picker.

It also supports theming and styling.

It has slots to display anything we want like changing the icons, input, header, or footer.

vue-click-outside

vue-click-outside is another Vue plugin that lets us handle clicks outside an element.

To install it, we run:

npm i vue-click-outside

Then we can use it by writing:

<template>
  <div>
    <div v-click-outside="hide" @click="toggle">Toggle</div>
    <div v-show="opened">Popup</div>
  </div>
</template>

<script>
import ClickOutside from "vue-click-outside";

export default {
  data() {
    return {
      opened: false
    };
  },
  directives: {
    ClickOutside
  },
  methods: {
    toggle() {
      this.opened = true;
    },

    hide() {
      this.opened = false;
    }
  }
};
</script>

We have a div that toggles a pop-up item on and off.

The click listener toggles the pop up on and it’ll be off when we click outside it.

Conclusion

v-click-outside and v-click-outside are plugins that let us handle clicks outside an element.

vue2-datepicker lets us add a date picker that’s very customizable.

vue-tmn-tabs lets us add tabs to a page.

Categories
Top Vue Packages

Top Vue Packages for Pagination, Star Rating, Grid Layout, and Date Picker

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 pagination, star rating input, grid layout, and date picker

vue-pagination-2

vue-pagination-2 is a pagination component that we can use to add those links.

To use it, we install it by running:

npm i vue-pagination-2

Then we can use it by writing:

<template>
  <div>
    <pagination v-model="page" :records="300" @paginate="myCallback"></pagination>
  </div>
</template>

<script>
import Pagination from "vue-pagination-2";

export default {
  components: {
    Pagination
  },
  data() {
    return {
      page: 2
    };
  },
  methods: {
    myCallback(e) {
      console.log(e);
    }
  }
};
</script>

We add the pagination component and bind the link with the page state with the pagination .

records is the number of records.

We can listen to the paginate event to get the page number.

vue-grid-layout

We can use the vue-grid-layout to create a flexible grid layout.

First, we install it by running:

npm i vue-grid-layout

Then we can write:

<template>
  <div>
    <grid-layout
      :layout.sync="layout"
      :col-num="12"
      :row-height="30"
      :is-draggable="true"
      :is-resizable="true"
      :is-mirrored="false"
      :vertical-compact="true"
      :margin="[10, 10]"
      :use-css-transforms="true"
    >
      <grid-item
        v-for="item in layout"
        :x="item.x"
        :y="item.y"
        :w="item.w"
        :h="item.h"
        :i="item.i"
        :key="item.i"
      >{{item.i}}</grid-item>
    </grid-layout>
  </div>
</template>

<script>
import VueGridLayout from "vue-grid-layout";
const layout = [
  { x: 0, y: 0, w: 2, h: 2, i: "0" },
  { x: 2, y: 0, w: 2, h: 4, i: "1" },
  { x: 4, y: 0, w: 2, h: 5, i: "2" }
];

export default {
  components: {
    GridLayout: VueGridLayout.GridLayout,
    GridItem: VueGridLayout.GridItem
  },
  data() {
    return {
      layout
    };
  }
};
</script>

to use it.

We set the layout of the grid.

x is the horizontal position of the item, y is the vertical position of the item.

i is the unique identifier of the item.

w is the width.

h is the height.

is-draggable makes the items draggable.

is-resizable makes the items resizable.

margin adds the horizontal and vertical margins.

vue-datetime

vue-datetime is a date-time picker component for Vue apps.

To install it, we run:

npm i vue-datetime luxon

Luxon is a dependency used for date formatting.

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import { Datetime } from "vue-datetime";
import "vue-datetime/dist/vue-datetime.css";

Vue.component("datetime", Datetime);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <datetime v-model="date"></datetime>
    <p>{{date}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      date: undefined
    };
  }
};
</script>

We register the component and use v-model to bind the select date to date .

Also, we have to remember to include the bundled CSS.

vue-js-toggle-button

vue-js-toggle-button is a toggle button component for Vue apps.

To use it, we install it by running:

npm i vue-js-toggle-button

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import ToggleButton from "vue-js-toggle-button";

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

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

App.vue

<template>
  <div>
    <toggle-button v-model="toggle"/>
    <p>{{toggle}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      toggle: false
    };
  }
};
</script>

We use the toggle-button component to add the toggle component.

And it binds the toggle value to toggle with v-model .

We can also change the color or add a label.

To add all that, we write:

<template>
  <div>
    <toggle-button v-model="toggle" color="green" :sync="true" :labels="true"/>
    <p>{{toggle}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      toggle: false
    };
  }
};
</script>

vue-star-rating

We can use the vue-star-rating widget to add a star rating input to our Vue app.

To use it, we install it by running:

npm i vue-star-rating

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import StarRating from "vue-star-rating";

Vue.component("star-rating", StarRating);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <star-rating v-model="rating"></star-rating>
    <p>{{rating}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      rating: 0
    };
  }
};
</script>

We use the star-rating component and bind the selected value with v-model .

Conclusion

vue-pagination-2 is a pagination widget.

vue-grid-layout lets us create a flexible grid layout where the items can be dragged and resized.

vue-js-toggle-button is a toggle switch component.

vue-star-rating is a handy star rating input.

Categories
Top Vue Packages

Top Vue Packages for Adding Telephone Input, Numeric Input, Dialog Boxes, and Tables

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 telephone input, dialog boxes, numeric inputs, and tables.

vue-tel-input

vue-tel-input is a package that lets us add a phone number input to a Vue app.

To install it, we run:

npm i vue-tel-input

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueTelInput from "vue-tel-input";

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

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

App.vue

<template>
  <div>
    <vue-tel-input v-model="phone"></vue-tel-input>
    <p>{{phone}}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      phone: ""
    };
  }
};
</script>

We have the vue-tel-input which we can bind the input value with v-model .

Now we should see a dropdown which shows the country.

Then we can enter the phone number in the input box.

It provides us with many options like setting the default country, max length, placeholder, focus, and more.

It also emits events when the input value is changed, when the country is changed, and more.

Also, it provides a slot for changing the arrow icon.

vue-numeric

vue-numeric lets us add a numeric input to our Vue app.

We can install it by running:

npm i vue-numeric

Then we can use it by writing:

<template>
  <div>
    <vue-numeric currency="$" separator="," v-model="price"></vue-numeric>
    <p>{{price}}</p>
  </div>
</template>

<script>
import VueNumeric from "vue-numeric";

export default {
  components: {
    VueNumeric
  },
  data() {
    return {
      price: 0
    };
  }
};
</script>

We use the vue-numeric component that comes with the package.

The currency is the string for the currency prefix.

separator is the thousands separator.

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

It also supports setting the min and max values for the number with min and max props.

We can also disable negative values.

Decimal precision can be changed with the precision prop.

The placeholder can be changed with the placeholder prop.

vue-good-table

vue-good-table is a package to add tables to our Vue app.

To use it, first we install it by running:

npm i vue-good-table

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueGoodTablePlugin from "vue-good-table";
import "vue-good-table/dist/vue-good-table.css";

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

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

App.vue

<template>
  <div>
    <vue-good-table :columns="columns" :rows="rows" :search-options="{
    enabled: true
  }"></vue-good-table>
  </div>
</template>

<script>
import { VueGoodTable } from "vue-good-table";

export default {
  components: {
    VueGoodTable
  },
  data() {
    return {
      columns: [
        {
          label: "first",
          field: "firstName"
        },
        {
          label: "last",
          field: "lastName"
        },
        {
          label: "age",
          field: "age",
          type: "number"
        }
      ],
      rows: [
        { firstName: "james", lastName: "smith", age: 20 },
        { firstName: "alex", lastName: "green", age: 34 }
      ]
    };
  }
};
</script>

We have the columns with an array of column definitions.

Each entry has at least the lavel and field properties.

type is the column type which we can optionally specify.

We use the vue-good-table component to display the table.

columns and rows have the respective props.

search-options lets us change the search options.

enabled will enable it.

We get a table with a search bar to search the rows with a few lines of code.

Sorting is also included by default.

vuejs-dialog

vue-dialog is a useful component for adding dialog boxes.

To use it, we install it by running:

npm i vuejs-dialog

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VuejsDialog from "vuejs-dialog";

import "vuejs-dialog/dist/vuejs-dialog.min.css";

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

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

App.vue

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

<script>
export default {
  async mounted() {
    const dialog = await this.$dialog.alert("success!");
    console.log("closed");
  }
};
</script>

We just register the plugin and use the this.$dialog.alert method to open a dialog box.

Conclusion

vue-tel-input lets us add a telephone input to our app.

vuejs-dialog is an easy to use package for us to add dialog boxes.

vue-good-table lets us add a table easily to our app.

vue-numeric is a useful numeric input.

Categories
Top Vue Packages

Top Vue Packages for Adding Lightbox, Charts, and Scrolling Display

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 lightbox, charts, and a scrolling display.

vue-easy-lightbox

vue-easy-lightbox is an easy to use lightbox component.

To use it, we install it by running:

npm i vue-easy-lightbox

Then we use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Lightbox from "vue-easy-lightbox";

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

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

App.vue

<template>
  <div>
    <vue-easy-lightbox visible :imgs="imgs" :index="index" @hide="handleHide"></vue-easy-lightbox>
  </div>
</template>

<script>
export default {
  methods: {
    handleHide() {}
  },
  data() {
    return {
      imgs: [
        "http://placekitten.com/200/200",
        "http://placekitten.com/201/201"
      ],
      index: 0
    };
  }
};
</script>

We have the vue-easy-lightbox component, which we use after we register it in main.js

imgs takes an array of URL strings of the images.

Now we see images and controls to navigate between images.

We can zoom and rotate images as we please.

It has many other options like disable the escape button, disabling the move button, and more.

vue-apexcharts

vue-apexcharts is a chart library made for Vue apps.

To install it, we run:

npm i vue-apexcharts apexcharts

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueApexCharts from "vue-apexcharts";
Vue.use(VueApexCharts);

Vue.component("apexchart", VueApexCharts);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <apexchart width="500" type="bar" :options="chartOptions" :series="series"></apexchart>
  </div>
</template>

<script>
export default {
  methods: {
    handleHide() {}
  },
  data() {
    return {
      chartOptions: {
        chart: {
          id: "example"
        },
        xaxis: {
          categories: [2011, 2012, 2013, 2014, 2015]
        }
      },
      series: [
        {
          name: "series",
          data: [30, 40, 35, 50, 49]
        }
      ]
    };
  }
};
</script>

xaxis.categories has the x-axis labels.

series has the data for the y-axis values.

type is the type of chart to display.

width is the width.

The series prop has the y-axis values.

options has all the options, including the x-axis data.

We can also change the colors:

<template>
  <div>
    <apexchart width="500" type="bar" :options="chartOptions" :series="series"></apexchart>
  </div>
</template>

<script>
export default {
  methods: {
    handleHide() {}
  },
  data() {
    return {
      chartOptions: {
        chart: {
          id: "example"
        },
        xaxis: {
          categories: [2011, 2012, 2013, 2014, 2015],
          labels: {
            style: {
              colors: ["red", "green"]
            }
          }
        }
      },
      series: [
        {
          name: "series-1",
          data: [30, 40, 35, 50, 49]
        }
      ]
    };
  }
};
</script>

vue-seamless-scroll

vue-seamless-scroll lets us add seamless scrolling to Vue apps.

First, we can the package by running:

npm i vue-seamless-scroll

Then we can use it by writing:

<template>
  <vue-seamless-scroll :data="listData" class="seamless-warp">
    <ul class="item">
      <li v-for="item in listData" :key="item.title">
        <span class="title" v-text="item.title"></span>
      </li>
    </ul>
  </vue-seamless-scroll>
</template>

<style scoped>
.seamless-warp {
  height: 229px;
  overflow: hidden;
}
</style>

<script>
export default {
  data() {
    return {
      listData: Array(100)
        .fill()
        .map((a, i) => ({
          title: `row ${i}`
        }))
    };
  }
};
</script>

We have a list of data that we loop through automatically.

Then title property of each row is displayed.

There are many other options to change the styling.

vue-silentbox

vue-silentbox is another lightbox component that we can use to display images and videos.

To install it, we run:

npm i vue-silentbox

Then we can use it by writing:

index.html

import Vue from "vue";
import App from "./App.vue";
import VueSilentbox from "vue-silentbox";

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

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

App.vue

<template>
  <div>
    <silent-box :gallery="images"></silent-box>
  </div>
</template>

<script>
export default {
  data() {
    return {
      images: [
        {
          src: "https://placekitten.com/200/200",
          description: "cat 1"
        },
        {
          src: "https://placekitten.com/201/201",
          description: "cat 2"
        }
      ]
    };
  }
};
</script>

We register the VueSlientBox plugin.

Then we pass in the images array into the gallery . When we click an image, we see the image displayed and the background is covered with a backdrop. It lets us set many other options like styles, autoplay, video controls, etc.

Conclusion

We can use vue-easy-lightbox or vue-silentbox to add a lightbox component to our Vue app. vue-seamless-scroll is a component that lets us create displays that scrolls automatically. vue-apexcharts lets us create charts easily. Thanks for reading my article, I hope you found it helpful!

Categories
Top Vue Packages

Top Vue Packages for Handling Local Storage, Adding Charts, Pagination, and Watching Visibility

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 handling local storage, adding charts, pagination, and watching visibility of elements.

vue-ls

vue-ls is a library to lets us work with local storage with our Vue app.

To install it, we can run:

npm i vue-ls

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Storage from "vue-ls";

const options = {
  namespace: "vuejs__",
  name: "ls",
  storage: "local"
};

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

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

App.vue

<template>
  <div id="app"></div>
</template>

<script>
export default {
  mounted() {
    this.$ls.set("foo", "bar", 60 * 60 * 1000);
  }
};
</script>

namespace is the prefix for the key.

name is the property name for accessing the vue-ls library.

Since the name is 'ls' , we can use Vue.ls or this.$ls to access it.

Then we can save an item with this.$ls.set with the key, value, and expiry time to save the item.

To get it item, we write:

this.$ls.get('foo');

We don’t need the prefix.

Also, we can watch for changes in local storage.

For instance, we can write:

const callback = (val, oldVal, uri) => {
  console.log('localStorage change', val);
}

this.$ls.on('foo', callback)

Then we can stop watching changes by writing:

this.$ls.off('foo', callback)

vue-observe-visibility

The vue-observe-visibility lets us watch for the visibility of an element.

To use it, we install it by running:

npm i vue-observe-visibility

Then we can use it by writing:

<template>
  <div id="app">
    <div v-observe-visibility="visibilityChanged" v-for="n in 100" :key="n">{{n}}</div>
  </div>
</template>

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

We hook the visibilityChanged handler to the v-observer-visibility directive to watch for visibility of the divs.

We can throttle the watching and disable it.

So we can write:

<template>
  <div id="app">
    <div
      v-observe-visibility="{
        callback: visibilityChanged,
        throttle: 300
      }"
      v-for="n in 100"
      :key="n"
    >{{n}}</div>
  </div>
</template>

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

to do the throttling.

vuejs-paginate

vuejs-paginate is a pagination link component that we can use to do pagination.

To install it, we run:

npm i vuejs-paginate

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Paginate from "vuejs-paginate";
Vue.component("paginate", Paginate);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div id="app">
    <p>{{page}}</p>
    <paginate
      :page-count="20"
      :click-handler="onClick"
      :prev-text="'Prev'"
      :next-text="'Next'"
      :container-class="'container'"
    ></paginate>
  </div>
</template>

<script>
export default {
  data() {
    return {
      page: 0
    };
  },
  methods: {
    onClick(e) {
      this.page = e;
    }
  }
};
</script>

We use the paginate component and then set the page-count property for the page count.

click-bandler is run when the links are clicked.

next-text is the next link text.

prev-text is the previous page link text.

container-class is the class for the container.

v-charts

v-charts is an easy to use chart library that’s based on echarts.

To install it, we run:

npm i v-charts echarts

We need echarts to use this library.

Then we can use it by writing:

<template>
  <div>
    <ve-line :data="chartData"></ve-line>
  </div>
</template>

<script>
import VeLine from "v-charts/lib/line.common";
export default {
  components: { VeLine },
  data() {
    return {
      chartData: {
        columns: ["date", "votes"],
        rows: [
          { date: "02-01", votes: 1231 },
          { date: "02-02", votes: 1223 },
          { date: "02-03", votes: 2523 },
          { date: "02-04", votes: 4723 },
          { date: "02-05", votes: 3723 }
        ]
      }
    };
  }
};
</script>

columns are the x and y-axis property names respectively.

rows have the property names we want to display as the value of the axes.

Conclusion

vue-ls lets us handle local storage functionality in Vue apps. vue-observe-visibility lets us watch observe the visibility of elements. vuejs-paginate is a useful pagination component. v-charts is an easy to use chart library. Thanks for reading my article, I hope you found it helpful!