Categories
Top Vue Packages

Top Vue Packages for Adding Charts, Unique IDs, Sliders, and Scroll Lock

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 charts, unique IDs, sliders, and scroll lock.

vue-unique-id

vue-unique-id lets us add a unique ID to our Vue component.

To use it, we run:

npm i vue-unique-id

to install it.

Then we write:

main.js

import Vue from "vue";
import App from "./App.vue";
import UniqueId from "vue-unique-id";
Vue.use(UniqueId);

Vue.config.productionTip = false;

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

App.vue

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

<script>
export default {
  created() {
    console.log(this.uid);
  }
};
</script>

We register the plugin and use the this.uid property to get the unique ID.

Also, we can get the ID with the $id method.

For instance, we can write:

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

<script>
export default {
  created() {
    console.log(this.$id("foo"));
  }
};
</script>

to get an ID with the 'foo' suffix added to it.

VueVisible

VueVisible is a directive that lets us display something conditionally.

To use it, we run:

npm i vue-visible

to install it.

Then we use it by writing:

<template>
  <div id="app">
    <div v-visible="isVisible">I'm visible</div>
  </div>
</template>

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

We just use the v-visible directive like the v-show directive to conditionally display something.

v-scroll-lock

v-scroll-lock lets us add a scroll lock to our Vue component to prevent scrolling.

To use it, we run:

npm i v-scroll-lock

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VScrollLock from "v-scroll-lock";

Vue.use(VScrollLock);

Vue.config.productionTip = false;

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

Modal.vue

<template>
  <div>
    <div class="modal" v-if="open">
      <button @click="closeModal">X</button>
      <div class="modal-content" v-scroll-lock="open">
        <p v-for="n in 100" :key="n">{{n}}</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Modal",
  data() {
    return {
      open: true
    };
  },
  methods: {
    openModal() {
      this.open = true;
    },
    closeModal() {
      this.open = false;
    }
  }
};
</script>

App.vue

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

<script>
import Modal from "./components/Modal";
export default {
  components: { Modal }
};
</script>

We have the Modal component with the v-scroll-lock directive applied to the content.

Now we won’t be able to scroll even though we have lots of content that overflow the screen.

Vue Glide

Vue Glide is a slider component for Vue apps.

To use it, we run:

npm i vue-glide-js

to install it.

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueGlide from "vue-glide-js";
import "vue-glide-js/dist/vue-glide.css";

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

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

App.vue

<template>
  <div id="app">
    <vue-glide>
      <vue-glide-slide v-for="i in 10" :key="i">Slide {{ i }}</vue-glide-slide>
    </vue-glide>
  </div>
</template>

<script>
import { Glide, GlideSlide } from "vue-glide-js";

export default {
  components: {
    [Glide.name]: Glide,
    [GlideSlide.name]: GlideSlide
  }
};
</script>

We use the vue-slide and vue-glide-slide component to display slides on the screen.

vue-chartist

vue-chartist is a chart library based of Chartist.js.

To use it, we run:

npm i vue-chartist chartist

to install it.

We use chartist for the CSS.

Then we write:

main.js

import Vue from "vue";
import App from "./App.vue";
Vue.use(require("vue-chartist"));

Vue.config.productionTip = false;

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

App.vue

<template>
  <div id="app">
    <chartist ratio="ct-major-second" type="Line" :data="chartData" :options="chartOptions"></chartist>
  </div>
</template>

<script>
import "chartist/dist/chartist.css";

export default {
  data() {
    return {
      chartData: {
        labels: ["A", "B", "C"],
        series: [[1, 3, 2], [4, 6, 5]]
      },
      chartOptions: {
        lineSmooth: false
      }
    };
  }
};
</script>

to use it.

We use the chartist component to create the graphs.

type is the kind of graph we want to create.

data has the labels and series data.

labels is for the x-axis, and series is for the y-axis.

chartOptions has the options. We set lineSmooth to false to disable line smoothing.

Conclusion

vue-unique-id creates a unique ID for our Vue components.

VueVisible is a directive that works like v-show.

v-scroll-lock disables scrolling in our elements.

Vue Glide lets us create a slider.

vue-chartist lets us create graphs with little effort.

Categories
Top Vue Packages

Top Vue Packages for Adding Input Masks, Modals, Date Manipulation, 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 adding input masks, modals, manipulating dates, and autocomplete dropdowns.

Vue IMask Plugin

Vue IMask Plugin is a Vue plugin that adds an input mask into our app.

We install it by running:

npm i vue-imask

Then we write:

<template>
  <imask-input
    v-model="numberModel"
    :mask="Number"
    radix="."
    @accept="onAccept"
    placeholder="Enter number"
  />
</template>

<script>
import { IMaskComponent } from "vue-imask";

export default {
  data() {
    return {
      numberModel: "",
      onAccept(value) {
        console.log(value);
      }
    };
  },
  components: {
    "imask-input": IMaskComponent
  }
};
</script>

to add the input with the mask.

It emits the accept event when the input is valid.

mask sets the format.

In our example, it’s a number.

v-model binds the value to a model state.

placeholder is the placeholder.

radix is the decimal separator.

@trevoreyre/autocomplete-vue is an easy to use autosggest component for Vue apps.

To use it, we run:

npm i @trevoreyre/autocomplete-vue

to install it.

Then we write:

main.js

import Vue from "vue";
import App from "./App.vue";
import Autocomplete from "@trevoreyre/autocomplete-vue";
import "@trevoreyre/autocomplete-vue/dist/style.css";

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

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

App.vue

<template>
  <div id="app">
    <autocomplete :search="search"></autocomplete>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fruits: ["apple", "orange", "grape", "banana"]
    };
  },
  methods: {
    search(input) {
      if (input.length < 1) {
        return [];
      }
      return this.fruits.filter(f => {
        return f.toLowerCase().startsWith(input.toLowerCase());
      });
    }
  }
};
</script>

to use it.

We register the plugin and import the CSS.

Then we add the autocomplete component to add the autocomplete input.

The search prop takes a function that lets us search for an item from an input value.

We pass the search method as the value.

input has the inputted value.

It returns an array of items that match.

The function can also return a promise.

We can also denounce the callback, change the base class, and set the default value.

vue-date-fns

vue-date-fns is a Vue wrapper for the vue-date-fns library.

To use it, we first install it by running:

npm i vue-date-fns

Then we can use it by writing:

<template>
  <div id="app">
    <div>{{ new Date() | date }}</div>
  </div>
</template>

<script>
import { dateFilter } from "vue-date-fns";

export default {
  filters: {
    date: dateFilter
  }
};
</script>

We register the filter and use it.

date formats the date into a date string.

We can also use the $date method to manipulate dates.

It also comes with locale data so we can switch to different locales.

We can also change the date format:

<template>
  <div id="app">
    <div>{{ new Date() | date('dd MMMM yyyy') }}</div>
  </div>
</template>

<script>
import { dateFilter } from "vue-date-fns";

export default {
  filters: {
    date: dateFilter
  }
};
</script>

We just pass in an argument into the filter function.

Vue my dropdown component

Vue my dropdown component is an easy to use dropdown component.

To use it, we run:

npm i vue-my-dropdown

to install it.

Then we write:

<template>
  <div id="app">
    <dropdown :visible="visible">
      <span class="link" @click="visible = !visible">click here</span>
      <div slot="dropdown" class="dialog">hello</div>
    </dropdown>
  </div>
</template>

<script>
import dropdown from "vue-my-dropdown";

export default {
  components: { dropdown },
  data() {
    return {
      visible: false
    };
  }
};
</script>

to use it.

It doesn’t come with any styles so we’ve to add them ourselves.

We populate the content of the dropdown slot to populate the dropdown.

We can set the position, add animation, and more.

Vuedals

Vuedals is a modal component for Vue apps.

To use it, we run:

npm i vuedals

to install it.

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import { default as Vuedals } from "vuedals";

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

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

App.vue

<template>
  <div id="app">
    <button @click="showModal()">show modal</button>
    <vuedal></vuedal>
  </div>
</template>

<script>
import {
  default as Vuedals,
  Component as Vuedal,
  Bus as VuedalsBus
} from "vuedals";

export default {
  components: {
    Vuedal
  },
  methods: {
    showModal() {
      VuedalsBus.$emit("new", {
        name: "modal",
        component: {
          name: "modal",
          template: `
            <div>
              <p>modal</p>
            </div>
          `
        }
      });
    }
  }
};
</script>

to use it.

We call the Vuedals.$emit method to open the modal.

The content is populated by a component.

Conclusion

Vue IMask Plugin is a simple input mask component.

@trevoreyre/autocomplete-vue is an autocomplete component for Vue apps.

vue-date-fns is a wrapper for date-fns for Vue apps.

Vue my dropdown component is a dropdown that we can customize.

Vuedals is a simple modal.

Categories
Top Vue Packages

Top Vue Packages for Adding Drag and Drop Animation, and Debouncing

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 drag and drop elements, animation, and debouncing.

Vue Slicksort

Vue Slicksort is an easy to use package that lets us create sortable lists in our Vue app in a snap.

To use it, we run:

npm i vue-slicksort

to install it.

Then we write:

<template>
  <div class="root">
    <SlickList lockAxis="y" v-model="items">
      <SlickItem v-for="(item, index) in items" :index="index" :key="index">{{ item }}</SlickItem>
    </SlickList>
  </div>
</template>

<script>
import { SlickList, SlickItem } from "vue-slicksort";

export default {
  components: {
    SlickItem,
    SlickList
  },
  data() {
    return {
      items: Array(20).fill().map((_, i)=> `item ${i}`)
    };
  }
};
</script>

to use it.

We use the SlickList item for creating the container.

Then we put SlickItem components inside it to display the sortable list.

Now we can drag and drop items on the list.

vue-dragula

vue-dragula is another easy to use drag and drop library for Vue apps.

To use it, we run:

npm i vue-dragula

Then we write:

main.js

import Vue from "vue";
import App from "./App.vue";
const VueDragula = require("vue-dragula");

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

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

App.vue

<template>
  <div class="root">
    <div class="container" v-dragula="colOne" bag="first-bag">
      <div v-for="text in colOne" :key="text">{{text}}</div>
    </div>
    <div class="container" v-dragula="colTwo" bag="first-bag">
      <div v-for="text in colTwo" :key="text">{{text}}</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      colOne: Array(15)
        .fill()
        .map((_, i) => `item ${i}`),
      colTwo: Array(15)
        .fill()
        .map((_, i) => `item ${i + 20}`)
    };
  }
};
</script>

We created 2 draggable lists with the v-dragula directive.

We set the bag prop to the same name so that we can drag and drop between them.

Inside each container, we render the elements that are draggable.

vue-dragscroll

vue-dragscroll is a directive that lets us enable scrolling by dragging our mouse.

To use it, we run:

npm i vue-dragscroll

to install it.

Then we write:

<template>
  <div class="root">
    <div v-dragscroll id="scroll">
      <div v-for="i in items" :key="i">{{i}}</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: Array(50)
        .fill()
        .map((_, i) => `item ${i}`)
    };
  }
};
</script>

<style>
#scroll {
  height: 300px;
  overflow-y: scroll;
}
</style>

to create a div that’s scrollable by clicking and holding our mouse and moving it.

We can use the x and y modifiers to only enable or disabling drag scrolling in one direction.

Also, we can disable drag scrolling for child elements.

Vue Animate CSS

Vue Animate CSS lets us add animation effects to our app without creating them from scratch ourselves.

We can install it by running:

npm i v-animate-css

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VAnimateCss from "v-animate-css";

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

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

App.vue

<template>
  <div class="root">
    <div v-animate-css="'fadeIn'">foo</div>
  </div>
</template>

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

We add a fade-in animation effect by using the v-animate-css directive with the string 'fadeIn' .

There are many other effects we can add to our app with this library.

vue-debounce

We can use vue-debounce to delay a callback’s running.

To use it, we run:

npm i vue-debounce

to install it.

Then we write:

main.js

import Vue from "vue";
import App from "./App.vue";
import vueDebounce from "vue-debounce";

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

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

App.vue

<template>
  <div class="root">
    <input v-debounce:300ms="log" type="text">
  </div>
</template>

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

We use the v-debounce directive with the 300ms modifier to delay the log method for 300 milliseconds before running it.

Then we can get the inputted value from it when we run it.

Conclusion

Vue Slicksort and vue-dragula let us add draggable elements to our app.

Vue Animate CSS is a library that lets us add CSS animation effects without writing them from scratch.

vue-debounce is a library for delaying callbacks.

Categories
Top Vue Packages

Top Vue Packages for Adding Autocomplete Input, Icons, Translations, and Highlight Words

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 autocomplete input, translations, icons, and highlight words.

vuejs-auto-complete

vuejs-auto-complete is an easy to use autocomplete component for Vue apps.

To use it, we run:

npm i vuejs-auto-complete

to install it.

Then we write:

<template>
  <div>
    <autocomplete :source="source"></autocomplete>
  </div>
</template>

<script>
import Autocomplete from "vuejs-auto-complete";

export default {
  components: {
    Autocomplete
  },
  data() {
    return {
      source: [{ id: 1, name: "foo" }, { id: 2, name: "bar" }]
    };
  }
};
</script>

to use it.

We use the autocomplete to add the input.

We pass the data source for the autofill dropdown to the source prop.

We can also get data for the autofill directly from an API.

So we can write:

<template>
  <div>
    <autocomplete
      source="https://api.github.com/search/repositories?q="
      results-property="items"
      results-display="full_name"
    ></autocomplete>
  </div>
</template>

<script>
import Autocomplete from "vuejs-auto-complete";

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

to do that.

source is the URL without the value of the query string.

results-property is the property for the array of results.

results-display is the property we display to the user.

We can also set request headers for the API request with the request-headers prop.

The entries can be formatted if we pass a function into the results-display prop.

vue-feather-icon

vue-feather-icon is a package that has icons we can use.

To use it, we install it by running:

npm i vue-feather-icon

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueFeatherIcon from "vue-feather-icon";

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

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

App.vue

<template>
  <div>
    <activity-icon></activity-icon>
  </div>
</template>

<script>
import { Activity } from "vue-feather-icon";

export default {
  components: {
    ActivityIcon: Activity
  }
};
</script>

We register the plugin and we can use the icon from the package.

vue-highlight-words

We can use the vue-highlight-words package to add text highlighting.

To install it, we run:

npm i vue-highlight-words

Then we can use it by writing:

main.js

<template>
  <div id="app">
    <Highlighter
      class="my-highlight"
      :style="{ color: 'red' }"
      highlightClassName="highlight"
      :searchWords="keywords"
      :autoEscape="true"
      :textToHighlight="text"
    />
  </div>
</template>

<script>
import Highlighter from "vue-highlight-words";

export default {
  name: "app",
  components: {
    Highlighter
  },
  data() {
    return {
      text: "The quick brown fox jumps over the lazy dog",
      words: "and or the"
    };
  },
  computed: {
    keywords() {
      return this.words.split(" ");
    }
  }
};
</script>

We use the Highlighter component display the text with highlight.

textToHighlight has the text we want to apply highlighting to.

searchWords has an array of strings that we want to highlight in the textToHighlight text.

style is the style we set to the base text.

autoEscape escapes the text if it’s true .

vue-multilanguage

vue-multilanguage is a plugin we can use to display translations on the screen,

To use it, we run:

npm i vue-multilanguage

to install it.

Then we can write:

import Vue from "vue";
import App from "./App.vue";
import { MLInstaller, MLCreate, MLanguage } from "vue-multilanguage";

Vue.use(MLInstaller);

export default new MLCreate({
  initial: "english",
  languages: [
    new MLanguage("english").create({
      title: "hello {0}!",
      msg: "You have {d} dogs"
    }),

    new MLanguage("french").create({
      title: "bonjour {0}!",
      msg: "Vous avez 5 chiens"
    })
  ]
});
Vue.config.productionTip = false;

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

App.vue

<template>
  <div id="app">
    <p v-text="$ml.get('myMessage')"/>
  </div>
</template>

<script>
import { MLBuilder } from "vue-multilanguage";

export default {
  name: "app",
  data() {
    return { dogs: 5 };
  },
  computed: {
    mlmyMessage() {
      return new MLBuilder("msg").with("d", this.dogs);
    }
  }
};
</script>

We register the plugin.

Then we use the MLCreate constructor to populate the translations and set the initial language.

Then in our App component, we use the $ml.get method to get the translation.

The argument is the property without the ml prefix.

We use MLBuilder to get the translation and call with to interpolate the placeholders.

Conclusion

vuejs-auto-complete lets us add an autocomplete input to our app.

vue-feather-icon is a collection of icons we can use in our Vue app.

vue-highlight-words is a component that lets us highlight part of a piece of text.

vue-multilanguage lets us localize our app with translations.

Categories
Top Vue Packages

Top Vue Packages for Entering Text, File Uploading, and Rendering Trees

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 draggable and resizable elements, file uploading, text editor, displaying tree structures, and input mask.

v-file-upload

We can use the v-file-upload package to add a file upload component to our Vue app.

To use it, we run:

npm i v-file-upload

to install it.

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";

import FileUpload from "v-file-upload";

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

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

App.vue

<template>
  <file-upload :url="url" :thumb-url="thumbUrl" :headers="headers" @change="onFileChange"></file-upload>
</template>

<script>
import Vue from "vue";

export default {
  data() {
    return {
      url: "http://upload.url",
      headers: { "access-token": "<your-token>" },
      filesUploaded: []
    };
  },
  methods: {
    thumbUrl(file) {
      return file.thumnbnail;
    },
    onFileChange(file) {
      this.fileUploaded = file;
    }
  }
};
</script>

to use it.

We use the file-upload component.

We set the url prop to set the upload URL.

headers has the headers.

thumbUrl has the URL to the thumbnail.

Now we see a file selector on our screen.

vue-jstree

vue-jstree is a tree view for Vue apps.

To use it, we run:

npm i vue-jstree

to install it.

Then we write:

<template>
  <div>
    <v-jstree :data="data"></v-jstree>
  </div>
</template>

<script>
import VJstree from "vue-jstree";

export default {
  components: {
    VJstree
  },
  data() {
    return {
      data: [
        {
          text: "apple",
          children: [
            {
              text: "orange",
              selected: true
            },
            {
              text: "danger",
              icon: "fa fa-warning icon-state-danger"
            }
          ]
        },
        {
          text: "grape"
        }
      ]
    };
  }
};
</script>

to use it.

We use the v-jstree to include the tree view in our component.

The nodes are defined by arrays.

Each entry is an object with the text property for the text.

selected is an optional property to indicate selection.

icon os the class for the icon.

children is the class for the children.

We can change the icon class.

It takes a few props.

show-checkbox indicates whether to show a checkbox.

multiple lets us select multiple items.

collapse sets all tree nodes to the collapsed state.

loading-text is a loading function.

There are many more props it takes.

Vue-Trix Text Editor

Vue-Trix Text Editor is a rich text editor that we can use in our Vue app.,

To use it, we run:

npm i vue-trix

to install the package.

Then we write:

<template>
  <div>
    <VueTrix v-model="editorContent" placeholder="Enter content" localStorage/>
  </div>
</template>

<script>
import VueTrix from "vue-trix";

export default {
  components: {
    VueTrix
  },
  data(){
    return {
      editorContent: ''
    }
  }
};
</script>

to add the editor.

We add the VueTrix component to add it to our app.

We set a value for the placeholder to add a placeholder.

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

localStorage save the inputted text to local storage.

vue-drag-resize

vue-drag-resize is an easy to use plugin to let us add draggable and resizable elements.

We install it by running:

npm i vue-drag-resize

Then we write:

<template>
  <div id="app">
    <VueDragResize isActive :w="200" :h="200" v-on:resizing="resize" v-on:dragging="resize">
      <p>{{ top }} х {{ left }}</p>
      <p>{{ width }} х {{ height }}</p>
    </VueDragResize>
  </div>
</template>

<script>
import VueDragResize from "vue-drag-resize";

export default {
  name: "app",

  components: {
    VueDragResize
  },

  data() {
    return {
      width: 0,
      height: 0,
      top: 0,
      left: 0
    };
  },

  methods: {
    resize(newRect) {
      this.width = newRect.width;
      this.height = newRect.height;
      this.top = newRect.top;
      this.left = newRect.left;
    }
  }
};
</script>

to use it.

We use the VueDraggable component to create a draggable and resizable component.

isActive sets the component to be active.

We set the initial height with the h prop.

The w prop is the initial width.

We listen to the resizing and dragging events to get the values of the new dimensions.

Conclusion

v-file-upload is a file upload component.

vue-jstree lets us display tree structures.

Vue-Trix Text Editor is a rich text editor for Vue apps.

vue-drag-resize lets us drag and resize elements.