Categories
Top Vue Packages

Top Vue Packages for Adding Tooltips, Dropdowns, and Manage Cookies.

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 tooltips, manage cookies, and add dropdowns.

VueTippy

VueTippy lets us add tooltips to a Vue app with ease.

To use it, we install it by writing:

npm i vue-tippy

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueTippy, { TippyComponent } from "vue-tippy";

Vue.use(VueTippy);
Vue.component("tippy", TippyComponent);

Vue.config.productionTip = false;

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

We register the VueTippy plugin and register the TippyComponent .

Then we can use the v-tippy directive by writing:

<template>
  <div>
    <button content="hello" v-tippy>click me</button>
  </div>
</template>

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

We just set the content to what we want.

Now we get a tooltip when we hover over it.

To customize the tooltip display, we can use the tippy component and populate the provided slots to add the content we want.

For example, we can write:

<template>
  <div>
    <tippy arrow>
      <template v-slot:trigger>
        <button>click me</button>
      </template>

      <div>
        <h3>Header</h3>
        <p style="color: black">{{ message }} - data binding</p>
      </div>
    </tippy>
  </div>
</template>

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

We add the tippy component and add the element that triggers the tooltip in the trigger slot.

The default slot has the content for the tooltip.

vue-cookie

vue-cookie lets us manage cookies the way we want.

To install it, we write:

npm i vue-cookie

Now we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
const VueCookie = require("vue-cookie");

Vue.use(VueCookie);

Vue.config.productionTip = false;

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

to register the VueCookie plugin.

Then we can save a cookie by writing:

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

<script>
export default {
  mounted() {
    this.$cookie.set("test", "hello", 1);
  }
};
</script>

We save the cookie easily with this.

The first argument is the cookie name, the 2nd is the value, the 3rd is the expiry time in days.

It’s much easier than saving cookies without a library.

To get a cookie, we can write:

this.$cookie.get('test');

And we can delete a cookie by writing:

this.$cookie.delete('test');

We can also change the domain and expiry time of the cookie by writing:

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

<script>
export default {
  mounted() {
    this.$cookie.set("test", "hello", { expires: 1, domain: "localhost" });
  }
};
</script>

We can set the cookie expiry time and domain.

There are other ways to do this.

vue-multiselect

vue-multiselect is a versatile dropdown component for Vue apps.

To install it, we run:

npm i vue-multiselect

Then we can use it by writing:

<template>
  <div>
    <multiselect
      v-model="selected"
      :options="options">
    </multiselect>
  </div>
</template>

<script>
  import Multiselect from 'vue-multiselect'
  export default {
    components: { Multiselect },
    data () {
      return {
        selected: null,
        options: ['foo', 'bar', 'baz']
      }
    }
  }
</script>

<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>

We use the multiselect component to create a dropdown.

v-model binds the selected value to a state.

options lets us set the options for the dropdown.

The style tag has the styles.

It supports many other options like Vuex integration, multi-select, tag input, and more.

vue-cookies

vue-cookies is another Vue library that lets us manage cookies in a Vue app.

To install it, we run:

npm i vue-cookies

Now we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueCookies from "vue-cookies";
Vue.use(VueCookies);

Vue.$cookies.config("30d");

Vue.config.productionTip = false;

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

App.vue

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

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

In main.js , we registered the plugin and set a global config.

We set all cookies created by vue-cookies to expire in 30 days.

In our component, we set a cookie with this.$cookies.set ,

The first argument is the key and the 2nd is the corresponding value.

The 3rd argument is the expiry time in seconds.

For instance, we can write:

this.$cookies.set("foo", "bar", 1);

We can use the remove method to remove a cookie:

this.$cookies.remove("token");

Conclusion

vue-cookie and vue-cookies are both useful plugins for letting us add cookie management features into our Vue app.

VueTippy is a handy tooltip library.

vue-multiselect is a versatile dropdown library.

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!