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.

Categories
Top Vue Packages

Top Vue Packages for Changing Metadata, Drag and Drop, and Numeric Inputs

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 changing metadata of our app, adding drag and drop and adding numeric inputs.

vue-head

The vue-head package lets us change the meta tag of our app for better SEO.

First, we install it by running:

npm i vue-head

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueHead from "vue-head";

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

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

to register the plugin.

Then in our component, we can write:

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

<script>
export default {
  data(){
    return {
      title: 'title'
    }
  },
  head: {
    title() {
      return {
        inner: this.title
      };
    },
    meta: [{ name: "description", content: "My description", id: "desc" }]
  }
};
</script>

to set the title and meta tag values as we see fit.

We can also pass some options to Vue.use :

import Vue from "vue";
import App from "./App.vue";
import VueHead from "vue-head";

Vue.use(VueHead, {
  separator: "-",
  complement: "complement"
});
Vue.config.productionTip = false;

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

Then we add the separator and the complement text after the separator.

vue-nestable

We can use the vue-nestable to create a tree view that can have items that can be dragged and dropped.

To install it, we run:

npm i vue-nestable

Then we use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueNestable from "vue-nestable";

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

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

App.vue

<template>
  <div>
    <vue-nestable v-model="nestableItems">
      <vue-nestable-handle slot-scope="{ item }" :item="item">{{ item.text }}</vue-nestable-handle>
    </vue-nestable>
  </div>
</template>

<script>
export default {
  data() {
    return {
      nestableItems: [
        { id: 0, text: "foo" },
        { id: 1, text: "bar" },
        { id: 2, text: "baz" }
      ]
    };
  }
};
</script>

We register the plugin and used the vue-nestable component.

v-model has the items that we want to render. It’ll be set to the latest values as the items are dragged and dropped.

vue-nestable-handle has the list of items that are rendered.

They are draggable and they can be dropped at different levels.

The maximum depth and styling can be changed.

vue-slider-component

vue-slider-component lets us create a slider which we can use as a numeric input component.

We install it by running:

npm i vue-slider-component

Then we can use it by writing:

<template>
  <div>
    <vue-slider v-model="value"/>
    <p>{{value}}</p>
  </div>
</template>

<script>
import VueSlider from "vue-slider-component";
import "vue-slider-component/theme/antd.css";

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

We imported and registered the vue-slider component.

And we also imported the bundled CSS file.

v-model binds to the value of the slider.

vue-screen-size

We can use the vue-screen-size package to get the screen size of the screen that the app is displayed in.

To install it, we run:

npm i vue-screen-size

Then we can use it by writing:

<template>
  <div>{{$vssWidth }}x{{$vssHeight}}</div>
</template>

<script>
import VueScreenSize from "vue-screen-size";

export default {
  mixins: [VueScreenSize.VueScreenSizeMixin]
};
</script>

We add the package’s bundled mixin.

Then we can use the $vssWidth variable to get the width and $vssHeight to get the height of the screen.

vue-numeric-input

vue-numeric-input provides us with an easy to add numeric input that has increment and decrement buttons to let us change the values.

To install it, we run:

npm i vue-numeric-input

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueNumericInput from "vue-numeric-input";

Vue.use(VueNumericInput);

Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <vue-numeric-input v-model="value" :min="1" :max="10" :step="2"></vue-numeric-input>
  </div>
</template>

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

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

max is the max value that the input allows.

min is the min value that the input allows.

step is the number which the value increments or decrements by when we press the buttons.

Conclusion

We can add numeric inputs with vue-slider-component and vue-numeric-input.

vue-screen-size lets watch for screen size changes.

vue-head lets us set the metadata for our app.

vue-nestable lets us create a draggable list.

Categories
Top Vue Packages

Top Vue Packages for Adding QR Codes, Input Masks, Animation CSS, 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 QR codes, input masks, animation CSS, and file upload.

qrcode.vue

To add a QR code to our Vue app, we can use the qrcode.vue component.

To install it, we can run:

npm i qrcode.vue

Then we can use it by writing:

<template>
  <div>
    <qrcode-vue :value="value" :size="size" level="H"></qrcode-vue>
  </div>
</template>
<script>
import QrcodeVue from "qrcode.vue";

export default {
  data() {
    return {
      value: "https://example.com",
      size: 300
    };
  },
  components: {
    QrcodeVue
  }
};
</script>

We use the qrcode-vue component.

size changes the size.

level is the level of error correction. L for low, M for medium, Q for quantile, and H for high.

The background and foreground can also change.

It can also be rendered as a SVG or canvas.

vue-image-crop-upload

The vue-image-crop-upload component lets us create an image cropper with upload capability.

To install it, we run:

npm i vue-image-crop-upload

Then we can use it by writing:

<template>
  <div>
    <my-upload
      field="img"
      [@crop](http://twitter.com/crop "Twitter profile for @crop")-success="cropSuccess"
      [@crop](http://twitter.com/crop "Twitter profile for @crop")-upload-success="cropUploadSuccess"
      [@crop](http://twitter.com/crop "Twitter profile for @crop")-upload-fail="cropUploadFail"
      v-model="show"
      :width="300"
      :height="300"
      url="/upload"
      lang-type="en"
      :params="params"
      :headers="headers"
      img-format="png"
    ></my-upload>
    <img :src="imgDataUrl">
  </div>
</template>
<script>
import myUpload from "vue-image-crop-upload";

export default {
  data() {
    return {
      show: true,
      params: {
        token: "123456798",
        name: "avatar"
      },
      headers: {
        smail: "*_~"
      },
      imgDataUrl: ""
    };
  },
  components: {
    "my-upload": myUpload
  },
  methods: {
    toggleShow() {
      this.show = !this.show;
    },

    cropSuccess(imgDataUrl, field) {
      this.imgDataUrl = imgDataUrl;
    },
    cropUploadSuccess(jsonData, field) {
      console.log(jsonData, field);
    },
    cropUploadFail(status, field) {
      console.log(status, field);
    }
  }
};
</script>

v-model is used for showing and hiding the cropper.

The events are for listening to various cropping events.

The format can be changed.

lang sets the language of the cropper.

vue2-animate for Vue.js 2

vue2-animate for Vue.js 2 is a CSS animation library.

To install it, we run:

npm i vue2-animate

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import "vue2-animate/dist/vue2-animate.min.css";

Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <button @click="show = !show">toggle</button>
    <transition name="fade">
      <p v-if="show" style="animation-duration: 0.3s">hello</p>
    </transition>
  </div>
</template>
<script>
export default {
  data() {
    return {
      show: false
    };
  }
};
</script>

We add the CSS so that we can use them instead of writing our own CSS code.

Now we can just add the transition or transition-group without adding our own CSS.

Vue Input Mask

Vue Input Mask lets us add an input mask to our Vue app.

To use it, we install it by running:

npm i vue-text-mask

Then we use it by writing:

<template>
  <div>
    <label>Number</label>
    <masked-input
      type="text"
      name="phone"
      class="form-control"
      v-model="phone"
      :mask="[/d/, /d/, /d/]"
      :guide="false"
      placeholderChar="#"
    ></masked-input>
  </div>
</template>

<script>
import MaskedInput from "vue-text-mask";

export default {
  components: {
    MaskedInput
  },

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

We bind the value entered to the v-model with phone .

The mask prop sets the input format, and we set each character with a regex.

v-money

v-money is another input mask component, but it only works with entering currencies.

To install it, we run:

npm i v-money

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import money from "v-money";

Vue.use(money, { precision: 2 });
Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <money v-model="price" v-bind="money"></money>
    {{price}}
  </div>
</template>

<script>
import { Money } from "v-money";

export default {
  components: { Money },

  data() {
    return {
      price: 0,
      money: {
        decimal: ",",
        thousands: ".",
        prefix: "$ ",
        suffix: " US",
        precision: 2,
        masked: false
      }
    };
  }
};
</script>

precision is the decimal number’s decision.

We set all the properties in money as props with v-bind="money" .

So we can set the decimal separator, thousands separator, prefix, suffix, and more.

Conclusion

qrcode.vue lets us add a QR code.

v-money lets us add a money input.

Vue Input Mask is a more versatile input mask component.

vue-image-crop-upload is an image cropper.

Categories
Top Vue Packages

Top Vue Packages for Adding Floating Action Buttons, Tables, Input Masks, and More

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 floating action buttons, handling clicks outside an element, input masks, and tables.

Vue Floating Action Button

Vue Floating Action Button lets us add a floating action button easily.

To install it, we run:

npm i vue-float-action-button

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueFab from "vue-float-action-button";

Vue.use(VueFab, {
  iconType: "MaterialDesign"
});
Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <vue-fab mainBtnColor="green">
      <fab-item @clickItem="clickItem" :idx="0" title="foo" icon="done"/>
      <fab-item @clickItem="clickItem" :idx="1" title="bar" icon="toc"/>
      <fab-item @clickItem="clickItem" :idx="2" title="baz" icon="done"/>
    </vue-fab>
  </div>
</template>

<script>
export default {
  methods: {
    clickItem() {
      alert("clicked");
    }
  }
};
</script>

We register the plugin.

Then we can use the vue-fab component, which houses a group of floating buttons.

mainBtnColor is the background color of the main button.

One button can trigger multiple buttons to be shown.

The buttons that are shown are the fab-item components.

It supports many other customization options, like changing shadow, auto show and hide, and more.

The title color and background color can also be changed.

vue-tables-2

vue-tables-2 is a package that lets us create customizable tables in Vue.

To use it, first we install it by running:

npm i vue-tables-2

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import { ClientTable } from "vue-tables-2";
Vue.use(ClientTable, {}, false, "bootstrap3");

Vue.config.productionTip = false;

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

We use Vue.use with a few arguments.

The first is the plugin itself.

The 2nd is global options.

The 3rd indicates that we don’t want to use Vuex.

The 4th is the name of the theme.

App.vue

<template>
  <div>
    <v-client-table :data="tableData" :columns="columns" :options="options"/>
  </div>
</template>

<script>
export default {
  data() {
    return {
      columns: ["id", "name", "age"],
      tableData: [
        { id: 1, name: "james", age: "20" },
        { id: 2, name: "jane", age: "24" },
        { id: 3, name: "joe", age: "16" },
        { id: 4, name: "alex", age: "55" },
        { id: 5, name: "may", age: "40" }
      ],
      options: {}
    };
  }
};
</script>

We created a basic table in App with the v-client-table component.

This means the data is on the client-side.

We pass in tableData to the data prop.

columns have the columns.

options has the options, which are optional.

Now we get a table with a filter input to let us search the entries.

The number of records is also displayed.

Maska

Maska is a package that lets us add an input mask into our Vue app.

To install it, we run:

npm i maska

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import Maska from "maska";
Vue.use(Maska);

Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <input v-maska="'###'" v-model="value">
    <p>{{value}}</p>
  </div>
</template>

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

We just register the plugin and use the v-maska directive.

The value we passed into the directive is the format string we want for the mask.

We can also add a custom pattern.

We can write:

<template>
  <div>
    <input v-model="value" v-maska="{ mask: 'z*', tokens: { 'z': { pattern: /[a-zA-Z]/ }}}">
    <p>{{value}}</p>
  </div>
</template>

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

We defined our own placeholder z to make people enter letters only with a regex.

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.

Conclusion

Vue Floating Action Button lets us add floating action buttons.

vue-tables-2 lets us add tables.

Maska lets us add input masks.

v-click-outside-x lets us handle clicks outside an element.

Categories
Top Vue Packages

Top Vue Packages for Adding a Date Picker, Cookie Dialog Box, and Scrolling

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 date pickers, scrolling, and cookie dialog box.

Vue date pick

Vue date pick is a lightweight and responsive date time picker.

We can use it by running:

npm install vue-date-pick

to install the package.

Then our component, we write:

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

<script>
import DatePick from "vue-date-pick";
import "vue-date-pick/dist/vueDatePick.css";

export default {
  components: { DatePick },
  data() {
    return {
      date: "2020-01-01"
    };
  }
};
</script>

We set the initial date in the data method.

Then we use the bundled date-pick component to add the date picker.

v-model binds the selected value to date .

It also comes with CSS to style the date picker.

vue-scroll

vue-scroll is a package with a directive that watches scrolling.

To use it, we run:

npm i vue-scroll

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import vuescroll from "vue-scroll";

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

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

App.vue

<template>
  <div v-scroll="onScroll" style="height: 200px; overflow-y: scroll">
    <ul>
      <li v-for="n in 100" :key="n">{{n}}</li>
    </ul>
  </div>
</template>

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

We have div with a fixed height.

overflow-y is set to scroll so the div will scroll when it overflows.

We have 100 rows of items so it’ll definitely scroll.

When it scrolls onScroll will be called because of the v-scroll directive.

The e parameter is logged and we’ll see the content of it displayed in the log when we scroll.

We can throttle or denounce the running of the scroll handler.

To do that, we can write:

Vue.use(vuescroll, { throttle: 600 })

or:

Vue.use(vuescroll, { debounce: 600 })

We can also change the value we pass into the v-scroll directive an object and add the throttle or debounce modifier:

<template>
  <div
    v-scroll:throttle="{ fn: onScroll, throttle: 500 }"
    style="height: 200px; overflow-y: scroll"
  >
    <ul>
      <li v-for="n in 100" :key="n">{{n}}</li>
    </ul>
  </div>
</template>

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

throttle can be replaced with debounce .

Vue Cookie Law

Vue Cookie Law is a component that lets us display a cookie law message on our app.

It’s the message that’s displayed on many websites.

To use it, we install it by running:

npm i vue-cookie-law

Then we can use it by writing:

main.js

<template>
  <footer>
    <cookie-law theme="blood-orange"></cookie-law>
  </footer>
</template>

<script>
import CookieLaw from "vue-cookie-law";
export default {
  components: { CookieLaw }
};
</script>

We just put the cookie-law component into our component.

It comes with a built-in message and a button.

We can style the dialog by styling the Cookie , Cookie__content , and Cookie__button class.

The message can be changed with the message prop.

Transitions, themes, button text, etc. all can change.

It can also store the cookie setting in local storage.

We can run a function when the button is clicked.

It has a slot for customizing content.

For instance, we can write:

<template>
  <footer>
    <cookie-law>
      <div slot-scope="props">
        <p>This site uses cookie</p>
        <button class="skew" @click="props.accept">
          <span>accept</span>
        </button>
        <button class="skew" @click="props.close">
          <span>decline</span>
        </button>
      </div>
    </cookie-law>
  </footer>
</template>

<script>
import CookieLaw from "vue-cookie-law";
export default {
  components: { CookieLaw }
};
</script>

We can also run our own function when the accept button is clicked.

For instance, we can write:

<template>
  <footer>
    <cookie-law @accept="thank"></cookie-law>
  </footer>
</template>

<script>
import CookieLaw from "vue-cookie-law";
export default {
  components: { CookieLaw },
  methods: {
    thank() {
      alert("thanks");
    }
  }
};
</script>

We listen to the accept event to run something when the accept button is clicked.

Conclusion

Vue date pick lets us add a lightweight and responsive date picker to our app.

vue-scroll is a package that has a directive to watch scrolling.

Vue Cookie Law is a component that has a cookies message. The setting is saved to local storage.