Categories
Top Vue Packages

Top Vue Packages for Adding Tables, Input Masks, and Scrolling to Element Feature

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 tables, input mask, and scrolling to an element.

vue-data-tables

The vue-data-tables package lets us add tables easily to our Vue app.

To install it, we run:

npm i vue-data-tables element-ui

Element UI is a dependency of vue-data-tables.

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueDataTables from "vue-data-tables";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import lang from "element-ui/lib/locale/lang/en";
import locale from "element-ui/lib/locale";

locale.use(lang);
Vue.use(ElementUI);
Vue.use(VueDataTables);

Vue.config.productionTip = false;

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

We imported the Element UI and vue-data-table plugins and registered them.

Also, we set the locale for the app.

The Element UI CSS is also imported.

App.vue

<template>
  <div>
    <data-tables :data="data" :pagination-props="{ pageSizes: [2, 5, 10, 15] }">
      <el-table-column type="selection" width="55"></el-table-column>

<el-table-column
        v-for="title in titles"
        :prop="title.prop"
        :label="title.label"
        :key="title.prop"
        sortable="custom"
      ></el-table-column>
    </data-tables>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [
        { id: 1, firstName: "james", lastName: "smith" },
        { id: 2, firstName: "jane", lastName: "smith" },
        { id: 3, firstName: "alex", lastName: "green" }
      ],
      titles: [
        {
          prop: "firstName",
          label: "first"
        },
        {
          prop: "lastName",
          label: "last"
        }
      ]
    };
  }
};
</script>

We set the data prop to set the data.

The title array has the prop and label properties to set the columns to display with the prop property.

label has the table headings.

By default we can sort the headers.

Pagination is also part of the basic table. We set the pagination-props prop to set the page sizes.

pageSizes property has the page sizes.

We also added a column with type set to selection to let us select the rows.

It also comes with many other customization options.

v-mask

v-mask lets us add input masks to our app.

We can install it by running:

npm i v-mask

To use it, we register the plugin and then use the input element with the v-mask directive:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueMask from "v-mask";
Vue.use(VueMask);

Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <input type="text" v-mask="'###-###-####'" v-model="phone">
    <p>{{phone}}</p>
  </div>
</template>

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

We have the v-mask directive set to the mask, which restricts the format of the input.

v-model binds to the phone state.

# means a digit, so we can only enter digits.

We can also use it as a filter, so we can write:

<template>
  <div>
    <span>{{ '1234567890' | VMask('(###) ###-####') }}</span>
  </div>
</template>

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

Then we get (123) 456–7890 displayed on the screen.

Other mask placeholders include A for letter, N for number or letter, X for any symbol, and ? for an optional character.

We can also customize the placeholders.

vue-scrollto

vue-scrollto is an easy to use directive for letting us add the scroll to element feature in our app.

To install it, we can run:

npm i vue-scrollto

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
const VueScrollTo = require("vue-scrollto");

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

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

App.vue

<template>
  <div>
    <a href="#" v-scroll-to="'#num-80'">Scroll to 80</a>
    <div :id="`num-${n}`" v-for="n in 100" :key="n">{{n}}</div>
  </div>
</template>

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

We have the element with the v-scroll-to directive set to the selector of the element we want to scroll to when it’s clicked.

Then we have the elements with the IDs we generated from v-for .

When we click the anchor, it’ll scroll to the element with ID num-80 .

It emits events that we can listen to and has options to change the animation.

Conclusion

We can use the vue-scrollto package to let us scroll to an element.

vue-data-tables let’s us add tables with pagination, sorting, and selection easily.

v-mask lets us add an input mask to our app.

Categories
Top Vue Packages

Top Vue Packages for Adding Async Computed Properties, and Carousel

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 pagination buttons, async computed properties, and carousels.

vue-async-computed

Vue components can’t have computed properties that are async.

However, with the addition of the vue-async-computed package, we can.

To install it, we run:

npm i vue-async-computed

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import AsyncComputed from "vue-async-computed";

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

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

App.vue

`<template>
  <div>
    <div>{{product}}</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      x: 2,
      y: 3
    };
  },
  asyncComputed: {
    product() {
      return new Promise(resolve =>
        setTimeout(() => resolve(this.x * this.y), 1000)
      );
    }
  }
};
</script>

We registered the plugin that came with the package,.

Then in our component, we return a promise that resolves to values derived from other states.

In our example, we just take the product of them and set that as the resolved value of the promise. We can set which properties to watch explicitly.

To do that, we write:

<template>
  <div>
    <div>{{product}}</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      x: 2,
      y: 3
    };
  },
  asyncComputed: {
    product: {
      get() {
        return new Promise(resolve =>
          setTimeout(() => resolve(this.x * this.y), 1000)
        );
      },
      watch: ["y"]
    }
  }
};
</script>

Then this,y ‘s value is watched and its new value recomputed if it changed.

vue-flicking

The vue-flicking library lets us add a carousel to our Vue app easily.

To use it, first we install it by running:

npm i @egjs/vue-flicking

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueFlicking from "@egjs/vue-flicking";

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

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

App.vue

<template>
  <div>
    <flicking
      :options="{ gap: 10, moveType: 'freeScroll' }"
      :tag="'div'"
      :viewportTag="'div'"
      @need-panel="e => {}"
      @move-end="e => {}"
    >
      <div v-for="n in 10" :key="n">slide {{n}}</div>
    </flicking>
  </div>
</template>

<script>
import { Flicking } from "@egjs/vue-flicking";

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

We set the gap between slides in pixels.

moveType is how the slides move.

tag is the tag to render for the slider.

viewportTag is the tag for the viewport.

We can also add plugins that are separate from the package.

To do that, we write:

<template>
  <div>
    <flicking
      :options="{ gap: 10, moveType: 'freeScroll' }"
      :tag="'div'"
      :viewportTag="'div'"
      :plugins="plugins"
      @need-panel="e => {}"
      @move-end="e => {}"
    >
      <div v-for="n in 10" :key="n">slide {{n}}</div>
    </flicking>
  </div>
</template>

<script>
import { Flicking } from "@egjs/vue-flicking";
import { Fade, AutoPlay } from "@egjs/flicking-plugins";

export default {
  components: {
    Flicking: Flicking
  },
  data() {
    return {
      plugins: [new Fade(), new AutoPlay(2000, "NEXT")]
    };
  }
};
</script>

We installed the plugin package with:

npm i @egjs/flicking-plugins

Then we added the Fade and AutoPlay plugins to add a fade effect and autoplay respectively.

2000 is the number of milliseconds before we move to the next slide.

vue-cookie-accept-decline

The vue-cookie-accept-decline package lets us add a banner for displaying a cookies message that’s seen frequently on websites.

To install it, we run:

npm i vue-cookie-accept-decline

Then we add the CSS to index.html between the head tags:

<link
  rel="stylesheet"
  type="text/css"
  href="https://unpkg.com/vue-cookie-accept-decline@5.2.3/dist/vue-cookie-accept-decline.css"
/>

Then we register the component by writing:

import Vue from "vue";
import App from "./App.vue";
import VueCookieAcceptDecline from "vue-cookie-accept-decline";
Vue.component("vue-cookie-accept-decline", VueCookieAcceptDecline);
Vue.config.productionTip = false;

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

in main.js

Next, we use it by writing:

<template>
  <div>
    <vue-cookie-accept-decline
      :ref="'myPanel1'"
      :elementId="'myPanel1'"
      :debug="false"
      :position="'bottom-left'"
      :type="'floating'"
      :disableDecline="false"
      :transitionName="'slideFromBottom'"
      :showPostponeButton="false"
      @status="cookieStatus"
      @clicked-accept="cookieClickedAccept"
      @clicked-decline="cookieClickedDecline"
    >
      <div slot="postponeContent">&times;</div>

      <div slot="message">
        We use cookies.
        <a href="https://example.com/" target="_blank">Learn More...</a>
      </div>

      <div slot="declineContent">OPT OUT</div>

      <div slot="acceptContent">GOT IT!</div>
    </vue-cookie-accept-decline>
  </div>
</template>

<script>
export default {
  methods: {
    cookieStatus() {},
    cookieClickedAccept() {},
    cookieClickedDecline() {}
  }
};
</script>

The setting of the button will be stored in local stored in local storage so it won’t show up again.

We’ll see the message in the message slot displayed.

The acceptContent slot has the accept button.

The declineContent slot has the decline button.

There are also events emitting for each button clicked.

clicked-accept is emitted when the accept button is clicked.

clicked-decline is emitted when the decline button is clicked.

status is emitted when the status is changed.

Conclusion

The vue-async-computed package us add async computed properties.

vue-cookie-accept-decline lets us add an accept cookie message.

vue-flicking lets us add a slideshow.

Categories
Top Vue Packages

Top Vue Packages for Adding a Kanban Board and Pagination Buttons

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 kanban board and adding pagination buttons.

vue-kanban

We can add a kanban board to our Vue app with the vue-kanban component.

The items in the kanban board can be dragged and dropped to different columns according to their status.

To install it, we run:

npm i vue-kanban

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import vueKanban from "vue-kanban";

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

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

styles.css

ul.drag-list,
ul.drag-inner-list {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.drag-container {
  max-width: 1000px;
  margin: 20px auto;
}

.drag-list {
  display: flex;
  align-items: flex-start;
}
[@media](http://twitter.com/media "Twitter profile for @media") (max-width: 500px) {
  .drag-list {
    display: block;
  }
}

.drag-column {
  flex: 1;
  margin: 0 10px;
  position: relative;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
}
@media (max-width: 500px) {
  .drag-column {
    margin-bottom: 30px;
  }
}
.drag-column h2 {
  font-size: 0.8rem;
  margin: 0;
  text-transform: uppercase;
  font-weight: 600;
}

.drag-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
}

.drag-inner-list {
  min-height: 50px;
  color: white;
}

.drag-item {
  padding: 10px;
  margin: 10px;
  height: 100px;
  background: gray;
}
.drag-item.is-moving {
  transform: scale(1.5);
  background: lightgray;
}

.drag-header-more {
  cursor: pointer;
}

.drag-options {
  position: absolute;
  top: 44px;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 10px;
  transform: translateX(100%);
  opacity: 0;
}
.drag-options.active {
  transform: translateX(0);
  opacity: 1;
}
.drag-options-label {
  display: block;
  margin: 0 0 5px 0;
}
.drag-options-label input {
  opacity: 0.6;
}
.drag-options-label span {
  display: inline-block;
  font-weight: 400;
  margin-left: 5px;
}

.gu-mirror {
  position: fixed !important;
  margin: 0 !important;
  z-index: 9999 !important;
  opacity: 0.8;
  list-style-type: none;
}

.gu-hide {
  display: none !important;
}

.gu-unselectable {
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
}

.gu-transit {
  opacity: 0.2;
}

The styles are derived from the starter styles at https://github.com/BrockReece/vue-kanban/blob/master/src/assets/kanban.css.

App.vue

<template>
  <div>
    <kanban-board :stages="stages" :blocks="blocks"></kanban-board>
  </div>
</template>

<script>
export default {
  data() {
    return {
      stages: ["not-started", "in-progress", "needs-review", "approved"],
      blocks: [
        {
          id: 1,
          status: "not-started",
          title: "Test"
        }
      ]
    };
  }
};
</script>

<style src='./styles.css'>
</style>

We need the CSS to style the kanban board since it comes with no styles.

In App.vue , we pass in the stages which is an array of strings.

blocks is an array of objects with the id , status , and title .

vuejs-paginate

vuejs-paginate is a pagination buttons component.

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>
    <div>page {{pageNum}}</div>
    <paginate
      :page-count="20"
      :click-handler="onClick"
      :prev-text="'Prev'"
      :next-text="'Next'"
      :container-class="'className'"
    ></paginate>
  </div>
</template>

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

We register the plugin in main.js .

Then we add the paginate component by passing a few props to enable navigation.

page-count has the page count.

click-handler is a function that’s run when a pagination button is clicked.

prev-text has the text for the previous button.

next-text has the text for the next button.

container-class has the class name for the pagination button container.

Now we’ll see a list of buttons that we can click to go to the page we want.

Conclusion

We can use vue-kanban to add a kanban board to our app.

The vuejs-paginate plugin lets us add pagination buttons for anything.

Categories
Top Vue Packages

Top Vue Packages for Adding Walkthroughs, Making HTTP Requests, and Validating Forms

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 walkthroughs, making HTTP requests, and validating forms.

vue-tour

We can use vue-tour to create walkthroughs for our app.

To use it, we write:

npm i vue-tour

Then we can register the components by writing:

import Vue from "vue";
import App from "./App.vue";
import VueTour from "vue-tour";

require("vue-tour/dist/vue-tour.css");
Vue.use(VueTour);

Vue.config.productionTip = false;

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

We also imported the styles.

Then we can use it by writing:

<template>
  <div>
    <div id="v-step-0">step 0.</div>
    <div class="v-step-1">step 1</div>
    <div data-v-step="2">step 2</div>
    <v-tour name="myTour" :steps="steps"></v-tour>
  </div>
</template>

<script>
export default {
  data() {
    return {
      steps: [
        {
          target: "#v-step-0",
          header: {
            title: "get started"
          },
          content: `hello <strong>world</strong>!`
        },
        {
          target: ".v-step-1",
          content: "step 1"
        },
        {
          target: '[data-v-step="2"]',
          content: "Step 2",
          params: {
            placement: "top"
          }
        }
      ]
    };
  },
  mounted() {
    this.$tours["myTour"].start();
  }
};
</script>

We have the list of steps in the template.

Then we have the steps array with the steps that target the elements that are on the page.

This way, the steps are displayed near the target element.

In each step, we can set the header, content, and placement of the steps.

Then to start the tour, we use the start method at the bottom of the page as we did.

vue-resource

vue-resource is an HTTP client that’s made as a Vue plugin.

To install it, we run:

npm i vue-resource

Then we can use it by writing:

import Vue from "vue";
import App from "./App.vue";
const VueResource = require("vue-resource");

Vue.use(VueResource);

Vue.config.productionTip = false;

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

to register the plugin.

Now we have access to the $http property in our component:

<template>
  <div>{{data.name}}</div>
</template>

<script>
export default {
  data() {
    return {
      data: {}
    };
  },
  async mounted() {
    const { body } = await this.$http.get("https://api.agify.io/?name=michael");
    this.data = body;
  }
};
</script>

It’s promised based so we can use async and await.

We can set common options that are used throughout the app by writing:

Vue.http.options.root = '/root';
Vue.http.headers.common['Authorization'] = 'Basic YXBpOnBhc3N3b3Jk';

We set the root URL for all requests and the Authorization header that’s used everywhere.

vue-form

vue-form is a form validation library for Vue apps.

We can use it by installing the package:

npm i vue-form

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueForm from "vue-form";

Vue.use(VueForm);

Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <vue-form :state="formState" [@submit](http://twitter.com/submit "Twitter profile for @submit").prevent="onSubmit">
      <validate tag="label">
        <span>Name *</span>
        <input v-model="model.name" required name="name">

<field-messages name="name">
          <div>Success!</div>
          <div slot="required">name is required</div>
        </field-messages>
      </validate>
    </vue-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      model: {
        name: ""
      },
      formState: {}
    };
  },
  methods: {
    onSubmit() {
      if (this.formState.$invalid) {
        return;
      }
    }
  }
};
</script>

We registered the component in main.js .

Then in the component, we used the vue-form component.

The state prop is set to the formState object, which will be updated when the form state change.

submit.prevent has the submit handler with e.preventDefault called on it.

v-model binds to the model.

The field-messages component displays the form validation messages.

required indicates that it’s required.

In the onSubmit method, we check the formState.$invalid to check whether the form is invalid.

If it’s invalid, we don’t proceed with submission.

Other form state properties include $name with the name attribute value of the field.

$valid to see if the form or field is valid.

$focused to check that the form or field is focused.

$dirty to see if the form or field has been manipulated.

It also comes with other validators like email, URL, number, min and max length, and more.

Conclusion

We can add a walkthrough tour to our Vue app with the vue-tour package.

vue-resource is a promise-based HTTP client that’s made for Vue apps.

vue-form is a useful form validation plugin for Vue apps.

Categories
Top Vue Packages

Top Vue Packages for Adding Avatar, Slides, and Tooltips

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 avatars, swiping, and tooltips.

vue-avatar

vue-avatar lets us add an avatar to our Vue app easily.

To use it, we run:

npm i vue-avatar

Then we can use it by importing the Avatar component:

<template>
  <div class="demo">
    <avatar username="Jane Smith"></avatar>
  </div>
</template>

<script>
import Avatar from "vue-avatar";

export default {
  name: "app",
  components: {
    Avatar
  }
};
</script>

We just set the name as the value of the username property to display a circle with the initials.

To add an image, we can use the src prop:

<template>
  <div class="demo">
    <avatar src="http://placekitten.com/200/200"></avatar>
  </div>
</template>

<script>
import Avatar from "vue-avatar";

export default {
  name: "app",
  components: {
    Avatar
  }
};
</script>

It also supports changing many other options like color, background, size, roundedness, custom styling, and more.

vue-awesome-swiper

The vue-awesome-swiper component lets us add a slider to add that we can swipe to our Vue app.

It’s great for creating carousels and slide shows.

To install it, we run:

npm i vue-awesome-swiper

Then we can use it by registering the plugin and importing the styles:

main.js

import Vue from "vue";
import App from "./App.vue";
import "swiper/css/swiper.css";
import VueAwesomeSwiper from "vue-awesome-swiper";
Vue.use(VueAwesomeSwiper);

Vue.config.productionTip = false;

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

Then we can use it in our component by writing:

<template>
  <swiper ref="mySwiper" :options="swiperOptions">
    <swiper-slide v-for="n in 10" :key="n">Slide {{n}}</swiper-slide>
    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
</template>

<script>
export default {
  name: "carrousel",
  data() {
    return {
      swiperOptions: {
        pagination: {
          el: ".swiper-pagination"
        }
      }
    };
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.$swiper;
    }
  },
  mounted() {
    this.swiper.slideTo(3, 1000, false);
  }
};
</script>

swiper-slide has the slides.

swiperOptions has the options. We set the button for changing slide to have the class swiper-pagination .

The swiper object is available in the this.$refs.mySwiper.$swiper property.

Then we can call methods on it like the slideTo method to slide to the slide with the given index.

1000 is the delay.

The 3rd argument indicates that we don’t want to run callbacks.

Alternatively, we can use it as a directive.

For instance, we can write:

<template>
  <div v-swiper:mySwiper="swiperOptions">
    <div class="swiper-wrapper">
      <div class="swiper-slide" :key="n" v-for="n in 10">
        <img src="http://placekitten.com/200/200">
        <p>slide {{n}}</p>
      </div>
    </div>
    <div class="swiper-pagination"></div>
  </div>
</template>

<script>
export default {
  name: "carrousel",
  data() {
    return {
      swiperOptions: {
        pagination: {
          el: ".swiper-pagination"
        }
      }
    };
  }
};
</script>

We used the v-swiper:mySwiper directive to create our swiper with the swiperOptions object.

Now we get the same slider, but without sliding automatically to the given slide.

The classes must be set so that we get the right items on the slide.

It can handle many events like clicking sides, transitions, and more.

v-tooltip

To add a tooltip to our Vue app, we can use the v-tooltip component.

To install it, we run:

npm i v-tooltip

Then we can use it by writing:

import Vue from "vue";
import App from "./App.vue";
import VTooltip from "v-tooltip";

Vue.use(VTooltip);

Vue.config.productionTip = false;

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

to register the components and directives.

Then in our component, we can write:

<template>
  <div>
    <button v-tooltip="`You have ${count} messages`">click me</button>
  </div>
</template>

<script>
export default {
  data() {
    return { count: 100 };
  }
};
</script>

to see a tooltip when we hover over the button.

The v-tooltip component lets us add the tooltip.

We can also change the position with some modifiers:

<template>
  <div>
    <button v-tooltip.right="`You have ${count} messages`">click me</button>
  </div>
</template>

<script>
export default {
  data() {
    return { count: 100 };
  }
};
</script>

We can also add classes so that we can style the tooltip:

<template>
  <div>
    <button
      v-tooltip.right="{ content: `You have ${count} messages`, classes: ['a', 'b'] }"
    >click me</button>
  </div>
</template>

<script>
export default {
  data() {
    return { count: 100 };
  }
};
</script>

We have the classes property in the object. content has the content.

Conclusion

The vue-avatar package lets us add an avatar easily.

The v-tooltip package is a great package for adding tooltips into our app.

vue-awesome-swiper lets us add slides to our app.