Categories
Top Vue Packages

Top Vue Packages for Animating Numbers, Handling Clicks, Edit Markdown, 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 the best packages for animating numbers, handling clicks outside an element, adding a Markdown editor, and a customizable dropdown.

vue-countup-v2

vue-countup-v2 lets us add a display for animating numbers.

To use it, we install it by running:

npm install --save countup.js vue-countup-v2

We’ve to add countup.js to use vue-countup-v2.

Then we can use it by writing:

<template>
  <div id="app">
    <ICountUp :delay="delay" :endVal="endVal" :options="options" @ready="onReady"/>
  </div>
</template>

<script>
import ICountUp from "vue-countup-v2";
export default {
  components: {
    ICountUp
  },
  data() {
    return {
      delay: 1000,
      endVal: 45373,
      options: {
        useEasing: true,
        useGrouping: true,
        separator: ",",
        decimal: ".",
        prefix: "",
        suffix: ""
      }
    };
  },
  methods: {
    onReady(instance, CountUp) {
      const that = this;
      instance.update(that.endVal + 100);
    }
  }
};
</script>

We can set many options.

We set the endVal to set the end value to animate.

delay is the delay for the animation.

useEasing lets us animate in a nonlinear fashion.

useGrouping groups the digits.

decimal is the decimal digits separator.

prefix and suffix are prefixes and suffixes that are added to the number.

Vue-SimpleMDE

Vue-SimpleMDE is a simple Markdown editor component for Vue apps.

To use it, we first install it by running:

npm i vue-simplemde

Then we can use it by writing:

<template>
  <vue-simplemde v-model="content" ref="markdownEditor"/>
</template>

<script>
import VueSimplemde from "vue-simplemde";
import "simplemde/dist/simplemde.min.css";

export default {
  components: {
    VueSimplemde
  },
  data() {
    return {
      content: ""
    };
  }
};
</script>

We just add the vue-simplemde component to our app.

Also, we imported the CSS for the package.

The inputted value is bound to the content with the v-model .

vue-search-select

vue-search-select provides us with a dropdown that’s customizable.

To use it, we run:

npm i vue-search-select

to install it.

Then we can use it by writing:

<template>
  <model-select :options="options" v-model="item" placeholder="select item"></model-select>
</template>

<script>
import { ModelSelect } from "vue-search-select";
import "vue-search-select/dist/VueSearchSelect.css";

export default {
  data() {
    return {
      options: [
        { value: "1", text: "foo" },
        { value: "2", text: "bar" },
        { value: "3", text: "baz" }
      ],
      item: {
        value: "",
        text: ""
      }
    };
  },
  components: {
    ModelSelect
  }
};
</script>

We use the model-select component.

The options prop sets the dropdown options.

v-model binds the item to the item .

vue-tel-input

vue-tel-input lets us ad a telephone number to our Vue app.

To use it, we install it by running:

npm i vue-tel-input

Then we can use it by writing:

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

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

We see a dropdown with the list of country prefixes for the phone numbers.

And we can type what we want into the vue-tel-input component.

v-model lets us bind the input value to the phone state.

vue-on-click-outside

vue-on-click-outside is a Vue directive that lets us call a method whenever a click is triggered outside the element.

To install it, we run:

npm i vue-on-click-outside

Then we can use it by writing:

<template>
  <div>
    <button type="button" @click="open">open</button>
    <div v-if="showPopover" v-on-click-outside="close">
      <span>hello</span>
    </div>
  </div>
</template>

<script>
import { mixin as onClickOutside } from "vue-on-click-outside";
export default {
  mixins: [onClickOutside],
  data() {
    return { showPopover: false };
  },
  methods: {
    open() {
      this.showPopover = true;
    },
    close() {
      this.showPopover = false;
    }
  }
};
</script>

We have a button to open a popup.

The popup has the v-on-click-outside directive to close it when we click outside the popup.

The closing is done by calling the close method.

Conclusion

vue-countup-v2 lets us animate numbers.

Vue-SimpleMDE lets us add a Markdown editor to our Vue app.

vue-tel-input is a useful telephone input.

vue-on-click-outside lets us handle clicks outside an element.

Categories
Top Vue Packages

Top Vue Packages for Adding Code Editors and Time Pickers

ue.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 the best packages for adding code editors and time pickers.

Vue-Codemirror-Lite

Vue-Codemirror-Lite is a code viewer for Vue apps.

It has syntax highlighti

To use it, we run:

npm i vue-codemirror-lite

to install it.

Then we can use it by writing:

<template>
  <codemirror :value="code"></codemirror>
</template>

<script>
import { codemirror } from "vue-codemirror-lite";

export default {
  components: {
    codemirror
  },
  data() {
    return {
      code: 'const str = "hello world"'
    };
  }
};
</script>

We just use the codemirror component to display the code.

Also, we can assign a ref and call methods on it:

<template>
  <codemirror ref="codeEditor" :value="code"></codemirror>
</template>

<script>
import { codemirror } from "vue-codemirror-lite";

export default {
  components: {
    codemirror
  },
  data() {
    return {
      code: 'const str = "hello world"'
    };
  },
  computed: {
    editor() {
      return this.$refs.codeEditor.editor;
    }
  },
  mounted() {
    this.editor.focus();
  }
};
</script>

Vue Prism Editor

Vue Prism Editor is another code editor for Vue apps.

To use it, we run:

npm i vue-prism-editor prism

to install it.

Prism is a required dependency.

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import "prismjs";
import "prismjs/themes/prism-tomorrow.css";
Vue.config.productionTip = false;

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

App.vue

<template>
  <prism-editor class="my-editor" :code="code" language="js"></prism-editor>
</template>

<script>
import PrismEditor from "vue-prism-editor";
export default {
  components: {
    PrismEditor
  },
  data() {
    return {
      code: `const a = 'foo'`
    };
  }
};
</script>

<style>
.my-editor {
  height: 300px;
}
</style>

We use the prism-editor component.

To display it, we set the height of the editor.

The code prop has the code.

language is set to js to indicate that we display JavaScript.

We can display line numbers with the linenumbers prop:

<template>
  <prism-editor lineNumbers class="my-editor" :code="code" language="js"></prism-editor>
</template>

<script>
import PrismEditor from "vue-prism-editor";
export default {
  components: {
    PrismEditor
  },
  data() {
    return {
      code: `const a = 'foo'`
    };
  }
};
</script>

<style>
.my-editor {
  height: 300px;
}
</style>

v-jsoneditor

v-jsoneditor is a JSON editor that’s made for Vue apps.

To use it, we run:

npm i v-jsoneditor

to install it.

Then we can use it by writing:

<template>
  <div>
    <v-jsoneditor v-model="json" :plus="false" height="400px" @error="onError"></v-jsoneditor>
  </div>
</template>

<script>
import VJsoneditor from "v-jsoneditor";

export default {
  name: "app",
  components: {
    VJsoneditor
  },
  data() {
    return {
      json: {
        hello: "world"
      }
    };
  },
  methods: {
    onError() {
      console.log("error");
    }
  }
};
</script>

We use the v-jsoneditor component to add it.

v-model binds the JSON value to the editor.

The error event is emitted and we can handle it with the onError method.

We can set some options with the options prop.

To use it, we write:

<template>
  <div>
    <v-jsoneditor v-model="json" :options="options" :plus="false" height="400px" @error="onError"></v-jsoneditor>
  </div>
</template>

<script>
import VJsoneditor from "v-jsoneditor";

export default {
  name: "app",
  components: {
    VJsoneditor
  },
  data() {
    return {
      json: {
        hello: "world"
      },
      options: {
        templates: [
          {
            text: "Person",
            title: "Insert a Person Node",
            className: "jsoneditor-type-object",
            field: "PersonTemplate",
            value: {
              firstName: "james",
              lastName: "smith"
            }
          }
        ]
      }
    };
  },
  methods: {
    onError() {
      console.log("error");
    }
  }
};
</script>

This allows us to add preset nodes by since we added the templates array with those fields.

plus lets us switch to full screen.

Vue2 Timepicker

Vue2 Timepicker is a handy time picker.

To use it, we run:

npm i vue2-timepicker

to install it.

Then we can write:

<template>
  <div>
    <vue-timepicker></vue-timepicker>
  </div>
</template>

<script>
import VueTimepicker from "vue2-timepicker";
import "vue2-timepicker/dist/VueTimepicker.css";

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

to use the timepicker.

We just add the vue-timerpicker component.

The format can be set and we can bind the selected value to a state:

<template>
  <div>
    <vue-timepicker v-model="time" format="HH:mm:ss"></vue-timepicker>
    <p>{{time}}</p>
  </div>
</template>

<script>
import VueTimepicker from "vue2-timepicker";
import "vue2-timepicker/dist/VueTimepicker.css";

export default {
  name: "app",
  components: {
    VueTimepicker
  },
  data() {
    return {
      time: undefined
    };
  }
};
</script>

We use v-model for binding and format to set the time format.

Conclusion

Vue-Codemirror-Lite and Vue Prism Editor are code editors for Vue apps.

v-jsoneditor is a JSON editor for Vue apps.

Vue2 Timepicker is a time picker.

Categories
Top Vue Packages

Top Vue Packages for Adding Calendars, Local Storage, Overlays, and Resizing

Vue.js is an easy to use web app framework that we can use to develop interactive front end apps.

In this article, we’ll look at how the best packages for adding calendars, overlays, and handle local storage.

vue-fullcalendar

vue-fullcalendar provides us with a simple calendar component to display events.

To use it, first we install it by running:

npm i vue-fullcalendar

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import fullCalendar from "vue-fullcalendar";

Vue.component("full-calendar", fullCalendar);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div id="app">
    <full-calendar :events="fcEvents" lang="en"></full-calendar>
  </div>
</template>

<script>
const fcEvents = [
  {
    title: "eat",
    start: "2020-05-25",
    end: "2020-05-27"
  }
];
export default {
  data() {
    return {
      fcEvents
    };
  }
};
</script>

We register the component. Then we used it in our App component.

full-calendar takes an events prop that takes an array of objects.

The objects have the title , start , and end properties.

title is the event title.

start is the start date string. end is the end date string.

It emits events when the month is changed and an event is clicked.

v-calendar

v-calendar is another calendar component.

To install it, we run:

npm i v-calendar

Now we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Calendar from "v-calendar/lib/components/calendar.umd";
import DatePicker from "v-calendar/lib/components/date-picker.umd";

Vue.component("calendar", Calendar);
Vue.component("date-picker", DatePicker);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div id="app">
    <date-picker :mode="mode" v-model="selectedDate"/>
  </div>
</template>

<script>
export default {
  data() {
    return {
      mode: "single",
      selectedDate: null
    };
  }
};
</script>

to add a date picker.

Also, we can write:

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

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

to add a calendar.

VueLocalStorage

VueLocalStorage is a Vue plugin that lets us handle local storage in Vue apps.

To install it, we run:

npm i vue-localstorage

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueLocalStorage from "vue-localstorage";

Vue.use(VueLocalStorage);
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.$localStorage.set('foo', 'bar')
  }
};
</script>

We register the plugin.

Then we can manipulate the local storage with the this.$localStorage property.

We can call get to get a value:

this.$localStorage.get('foo')

To remove an entry, we call remove :

this.$localStorage.remove('foo')

vue-loading-overlay

vue-loading-overlay provides us with an overlay that displays when something loads.

To install it, we run:

npm i vue-loading-overlay

Then we can use it by writing:

<template>
  <div>
    <loading active can-cancel :on-cancel="onCancel" is-full-page></loading>
  </div>
</template>

<script>
import Loading from "vue-loading-overlay";
import "vue-loading-overlay/dist/vue-loading.css";

export default {
  components: {
    Loading
  },
  methods: {
    onCancel() {}
  }
};
</script>

We use the loading component to add an overlay to show when data is loading.

active is a prop that’s set to true if we want to show the overlay.

can-cancel makes the overlay cancelable.

Then when we cancel the onCancel method is called because we set that as the value of the on-cancel prop.

We can also use it as a plugin.

For instance, we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import Loading from "vue-loading-overlay";
import "vue-loading-overlay/dist/vue-loading.css";

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

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

App.vue

<template>
  <div ref="container"></div>
</template>

<script>
export default {
  mounted() {
    this.$loading.show({
      container: this.$refs.container,
      canCancel: true,
      onCancel: this.onCancel
    });
  },
  methods: {
    onCancel() {}
  }
};
</script>

We access the this.$loading.show method to show the overlay.

The container property has is set to the ref of the container we want the overlay to be in so that it’ll be rendered.

onCancel has the method to call when it’s canceled.

Conclusion

vue-fullcalendar is a calendar and date picker component.

vue-loading-overlay is an overlay component that’s used when we load data.

VueLocalStorage is a plugin for handling local storage in Vue apps.

Categories
Top Vue Packages

Top Vue Packages for Adding Tabs, Popovers, Charts, and Display Code with

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 the best packages for adding tabs, popovers, charts, and display code with syntax highlighting.

vue-tabs-component

vue-tabs-component is a component that lets us add tabs to our Vue app.

To use it, we run:

npm i vue-tabs-component

Then we can use it by writing:

main.js

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

Vue.component("tabs", Tabs);
Vue.component("tab", Tab);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div id="app">
    <tabs :options="{ useUrlFragment: false }" @clicked="tabClicked" @changed="tabChanged">
      <tab name="First tab">tab 1</tab>
      <tab name="Second tab">tab 2</tab>
      <tab name="Disabled tab" :is-disabled="true">disabled</tab>
      <tab name="Custom fragment">fragment</tab>
    </tabs>
  </div>
</template>

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

We used the tab and tabs components to add the tabs. The name prop is displayed as the link names. And the content between the tab tags is the tab content.

vue-prism-component

vue-prism-component is a component to let us display code with syntax highlighting.

To use it, we run:

npm i vue-prism-component prismjs

to install the packages.

Prism is a required dependency since the component uses it.

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import "prismjs";
import "prismjs/themes/prism.css";
Vue.config.productionTip = false;

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

App.vue

<template>
  <prism language="javascript">{{ code }}</prism>
</template>

<script>
import Prism from "vue-prism-component";

export default {
  data() {
    return {
      code: "const a = b"
    };
  },
  components: {
    Prism
  }
};
</script>

We have the prism component and we set the language of the code we’re displaying with the language prop. Then we display the code in between the tags.

vue-js-popover

vue-js-popover lets us add a popover to our Vue app.

We can use it by running:

npm i vue-js-popover

to install it.

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import Popover from "vue-js-popover";

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

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

App.vue

<template>
  <div id="app">
    <button v-popover:foo>Toggle popover</button>

    <popover name="foo">Hello</popover>
  </div>
</template>
<script>
export default {};
</script>

We have the popover component to display a popover.

The name is used as a modifier in the v-popover directive to trigger it.

It’s triggered the button with the v-popover directive.

We change the position and toggle on and off the pointer.

For instance, we can write:

<template>
  <div id="app">
    <button v-popover:foo.right>Toggle popover</button>

    <popover name="foo">Hello</popover>
  </div>
</template>
<script>
export default {};
</script>

We use the right modifier to place the popover on the right.

vue-echarts-v3

vue-echarts-v3 is a chart library for Vue apps. It has support for many kinds of charts.

To use it, we run:

npm install --save echarts vue-echarts-v3

to install it.

Then we write:

<template>
  <div class="echarts">
    <IEcharts :option="bar" :loading="loading" @ready="onReady" @click="onClick"/>
  </div>
</template>

<script type="text/babel">
import IEcharts from "vue-echarts-v3";
export default {
  name: "view",
  components: {
    IEcharts
  },
  props: {},
  data () {
    return {
      loading: false,
      bar: {
        title: {
          text: "fruits"
        },
        tooltip: {},
        xAxis: {
          data: [
            "apple",
            "orange",
            "banana",
          ]
        },
        yAxis: {},
        series: [
          {
            name: "Sales",
            type: "bar",
            data: [5, 20, 36]
          }
        ]
      }
    }
  },
  methods: {
    onReady(instance, ECharts) {
      console.log(instance, ECharts);
    },
    onClick(event, instance, ECharts) {
      console.log(arguments);
    }
  }
};
</script>

<style scoped>
.echarts {
  width: 400px;
  height: 400px;
}
</style>

to create a chart.

The options prop lets us populate the data and labels for our graph.

title has the text prop which has the title.

xAxis has the x-axis labels.

series has the y-axis data.

type has the graph type.

We set the height and width of the graph with CSS.

When we click on the bars on the graph, onClick is run.

It has the data on the bar.

onReady is run when the graph loads.

Conclusion

vue-echarts-v3 is an easy to use chart library for Vue apps. vue-tabs-component lets us add tabs to our app. vue-prism-component is a component to let us display code with syntax highlighting. vue-js-popover is a handy popover component.

Categories
Top Vue Packages

Top Vue Packages for Dropdown, Date Pickers and Popups

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 dropdown with hierarchical selections, popups, and an auto-suggest input.

vue-treeselect

vue-treeselect provides us with a dropdown that’s hierarchical that we can use in our Vue app.

To use it, first we install it by running:

npm i @riophae/vue-treeselect

Then we can use it by writing:

<template>
  <div id="app">
    <treeselect v-model="value" multiple :options="options"/>
  </div>
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  components: { Treeselect },
  data() {
    return {
      value: null,
      options: [
        {
          id: 1,
          label: "a",
          children: [
            {
              id: 2,
              label: "foo"
            },
            {
              id: 3,
              label: "bar"
            }
          ]
        },
        {
          id: 4,
          label: "baz"
        },
        {
          id: 5,
          label: "qux"
        }
      ]
    };
  }
};
</script>

We have an options array that have all the options.

They can be nested with the children property.

This way, we’ll see them listed in the dropdown choices.

multiple enables multiple selections.

We’ve to remember to set the id to our choice.

vue-popperjs

vue-popperjs is a pop-up component for add tooltips to elements.

To use it, we first install it by running:

npm i vue-popperjs

Then we can use it by writing:

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

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

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

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

We use the popper component.

We set the trigger to clickToOpen to open the popup on click.

Vue FlatPickr Component

Vue FlatPickr Component is a date-time picker component.

To install it, we run:

npm i vue-flatpickr-component

Then we can use it by writing:

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

<script>
import flatPickr from "vue-flatpickr-component";
import "flatpickr/dist/flatpickr.css";

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

We use the flat-pickr component and bind the selected value to the date state.

flat-pickr will display a date-time picker.

We can also customize it with our own config.

For instance, we can write:

<template>
  <div>
    <flat-pickr v-model="date" :config="config"></flat-pickr>
    <p>{{date}}</p>
    <p></p>
  </div>
</template>

<script>
import flatPickr from "vue-flatpickr-component";
import "flatpickr/dist/flatpickr.css";
import { French } from "flatpickr/dist/l10n/fr.js";

export default {
  data() {
    return {
      date: null,
      config: {
        wrap: true,
        altFormat: "M j, Y",
        altInput: true,
        dateFormat: "Y-m-d",
        locale: French
      }
    };
  },
  components: {
    flatPickr
  }
};
</script>

We change the altFormat to set the date format.

dateFormat is the selected date format.

locale sets the locale.

wrap wraps the input.

vue-bootstrap-datetimepicker

Vue Bootstrap 4 DatetimePicker is a date-time picker that we can use.

To install it, we run:

npm i vue-bootstrap-datetimepicker

We then use the component by writing:

<template>
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <date-picker v-model="date" :config="options"></date-picker>
        <p>{{date}}</p>
      </div>
    </div>
  </div>
</template>

<script>
import "bootstrap/dist/css/bootstrap.css";
import datePicker from "vue-bootstrap-datetimepicker";
import "pc-bootstrap4-datetimepicker/build/css/bootstrap-datetimepicker.css";

export default {
  data() {
    return {
      date: new Date(),
      options: {
        format: "DD/MM/YYYY",
        useCurrent: false
      }
    };
  },
  components: {
    datePicker
  }
};
</script>

We use the date-picker component to add our date picker input.

v-model binds the selected date to the date variable.

options lets us add the options.

And we’ve to import the CSS to make it look right.

It uses Bootstrap’s style to style the date picker.

vue-autosuggest

vue-autosuggest is an input component that gives us suggestions of what to enter.

To use it, first we install it by running:

npm i vue-autosuggest

Then we use it by writing:

main.js

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

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

App.vue

<template>
  <div class="container">
    <vue-autosuggest
      :suggestions="[{data:['apple', 'orange' ,'grape']}]"
      :input-props="{id:'autosuggest', placeholder:`What's your favorite fruit?`}"
    >
      <template slot-scope="{suggestion}">
        <span class="my-suggestion-item">{{suggestion.item}}</span>
      </template>
    </vue-autosuggest>
  </div>
</template>

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

We add the input with the vue-autosuggest component.

Then we populate the default slot to display the choices our way.

Conclusion

vue-treeselect lets us add a dropdown with the with hierarchical selections.

vue-popperjs lets us add popups.

vue-bootstrap-datetimepicker is a simple date picker that uses Bootstrap styles.

vue-autosuggest is a autosuggestion input that we can use simply.