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 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 Adding Context Menu, Managing Session Storage, 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 affixing elements, managing session storage, adding draggable elements, pagination, and context menu.

vue-affix

We can use the vue-affix package to put an element before another element.

To use it, we run:

npm i vue-affix

Then we can use it by writing:

<template>
  <div>
    <affix class="sidebar" relative-element-selector="#section">
      <p>foo</p>
      <p>bar</p>
      <p>baz</p>
    </affix>
    <section id="section">
      <p>affix element</p>
    </section>
  </div>
</template>

<script>
import { Affix } from "vue-affix";

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

We set the relative-element-selector prop to the selector that we want to put the element before.

vue-context-menu

We can use vue-context-menu to show a context menu

To use it, we write:

npm i vue-context-menu

Then we can use it by writing:

<template>
  <div>
    <div @contextmenu.prevent="$refs.ctxMenu.open">right click</div>
    <context-menu id="context-menu" ref="ctxMenu">
      <li>option 1</li>
      <li>option 2</li>
    </context-menu>
  </div>
</template>

<script>
import contextMenu from "vue-context-menu";
export default {
  components: { contextMenu }
};
</script>

We listen to the contextmenu event and run $refs.ctxMenu.open to open the context menu.

In the context-menu component, we set the ref to ctxMenu so it can be opened.

We can put anything in our context menu.

vue-session

We can use the vue-session package to let us manage session storage.

To use it, we run:

npm i vue-session

Then we can use it by writing:

main.js

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

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

App.vue

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

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

We set a value in session storage using the this.$session property.

We can also use get to get the value by the key,.

getAll gets all values.

colear removes all keys.

destroy destroys the session.

renew renews a session.

start starts a new session.

exists checks if a key exists.

draggable-vue-directive

draggable-vue-directive lets us create a draggable component with ease.

To use it, we run:

npm i draggable-vue-directive

to install it.

Then we write:

<template>
  <div>
    <div v-draggable>drag me</div>
  </div>
</template>

<script>
import { Draggable } from "draggable-vue-directive";

export default {
  directives: {
    Draggable
  }
};
</script>

to create a basic draggable element.

All we have to do is to use the v-draggable directive.

Also, we can set a value for it and access it:

<template>
  <div>
    <div v-draggable="draggableValue">drag me</div>
  </div>
</template>

<script>
import { Draggable } from "draggable-vue-directive";

export default {
  directives: {
    Draggable
  },
  data() {
    return {
      draggableValue: {
        onPositionChange: this.onPosChanged
      }
    };
  },
  methods: {
    onPosChanged(positionDiff, absolutePosition, event) {
      console.log(positionDiff, absolutePosition);
    }
  }
};
</script>

The draggableValue object can have various methods that are called when actions are done to the draggable element.

onPositionChange is run when the position of the draggable element changes position.

positionDiff is the difference in positions from the previous.

absolutePosition is the current position.

Othe properties we can put in the object include handle , onDragEnd , resetInitialPos , initialPosition , and more.

vue-paginate

We can use the vue-paginate package to paginate anything.

To use it, we run:

npm i vue-paginate

Then we can use it by writing:

<template>
  <div>
    <paginate name="fruits" :list="fruits" :per="2">
      <li v-for="fruit in paginated('fruits')" :key="fruit">{{ fruit }}</li>
    </paginate>
    <paginate-links for="fruits"></paginate-links>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fruits: ["apple", "orange", "grape", "banana", "pear"],
      paginate: ["fruits"]
    };
  }
};
</script>

paginate has the paginated items.

per has the items per page.

We have the items to display inside the tags.

And pagination-links has the links to access each page.

Now we see the links for accessing each page, and the items on each page shown.

Conclusion

vue-affix lets us add an element as a sibling of another element.

vue-context-menu lets us add a context menu to our Vue app.

vue-paginate is a pagination component that we can use.

draggable-vue-directive lets us make draggable elements.

vue-session lets us manage session storage.

Categories
Top Vue Packages

Top Vue Packages for Adding Notifications, Progressive Image Loading, 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 notifications, progressive image loading, ripple effect, and password input.

vuejs-noty

vuejs-noty is a notification library for Vue apps.

To use it, we run:

npm i vuejs-noty

to install it.

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueNoty from "vuejs-noty";
import "vuejs-noty/dist/vuejs-noty.css";

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

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

to register the component and import the CSS.

App.vue

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

<script>
export default {
  mounted() {
    this.$noty.show("Hello!");
  }
};
</script>

to display the notification.

We can also change the configuration.

Then we can set the configuration by writing:

import Vue from "vue";
import App from "./App.vue";
import VueNoty from "vuejs-noty";
import "vuejs-noty/dist/vuejs-noty.css";

Vue.use(VueNoty, {
  timeout: 4000,
  progressBar: true,
  layout: "topCenter"
});
Vue.config.productionTip = false;

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

timeout is the duration to display.

progressBar displays a progress bar on the notification.

layout is the placement of the notification.

Material Ripple Effect

Material Ripple Effect is a directive to lets us add a ripple effect on an element.

To use it, we run:

npm i vue-ripple-directive

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import Ripple from "vue-ripple-directive";

Vue.directive("ripple", Ripple);
Vue.config.productionTip = false;

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

App.vue

<template>
  <div>
    <div v-ripple>button</div>
  </div>
</template>

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

We just import the directive and use it on an element.

We can add modifiers to change their behavior.

And we can also change the color of the ripple.

We can write:

<template>
  <div>
    <div v-ripple.mouseover.1500>button</div>
  </div>
</template>

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

We add the mouseover modifier to see the ripple effect on mouseover.

1500 is the duration of the effect.

We can also change the color:

<template>
  <div>
    <div v-ripple="'green'">button</div>
  </div>
</template>

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

Vue-APlayer

Vue-APlayer is an easy to use audio player for Vue apps.

To install it, we run:

npm i vue-aplayer

Then we can use it by running:

<template>
  <div>
    <aplayer
      autoplay
      :music="{
        title: 'sample',
        artist: 'musician',
        src: 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',
        pic: 'http://placekitten.com/200/200'
      }"
    />
  </div>
</template>

<script>
import Aplayer from "vue-aplayer";

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

title is the clip title.

artist is the artist’s name.

They’ll both be displayed on the screen.

src is the clip URL.

pic is the URL for the picture.

Then we can see an audio player and play the clip.

The picture is displayed on the player.

vue-password

We can add a password input with vue-password.

To install it, we run:

npm i vue-password

Then we can use it by writing:

<template>
  <div>
    <form>
      <label for="password">Password</label>
      <VuePassword v-model="password" id="password1" :strength="strength" type="text"/>
    </form>
  </div>
</template>

<script>
import VuePassword from "vue-password";

export default {
  components: {
    VuePassword
  },
  computed: {
    strength() {
      if (this.password.length > 4) {
        return 4;
      }
      return Math.floor(this.password.length / 4);
    }
  },
  data() {
    return {
      password: ""
    };
  }
};
</script>

We use the VuePassword component to add the input.

v-model binds the input value to the password state.

strength sets the strength meter.

There are slots to customize the password input, icon, strength meter, and more.

strength must return an integer between 0 and 4.

vue-progressive-image

We can use the vue-progressive-image to add an image element that loads progressively.

To use it, we run:

npm i vue-progressive-image

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueProgressiveImage from "vue-progressive-image";

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

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

App.vue

<template>
  <div>
    <progressive-img src="http://placekitten.com/200/200"/>
  </div>
</template>

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

Then we use the progressive-img component to show the image.

Also, we can use the progressive-background to add a background:

<template>
  <div>
    <progressive-background src="http://placekitten.com/200/200"/>
  </div>
</template>

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

Conclusion

vuejs-noty is a useful notification library.

Material Ripple Effect gives us ripple effect on elements.

vue-password lets us add a password input with a strength meter.

vue-progressive-image lets add an image element to load images progressively.

Categories
Top Vue Packages

Top Vue Packages for Formatting Currencies, Adding Text Area, 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 formatting currencies, adding a text area, letting users copy data to the clipboard, and adding a photo masonry grid.

vue-currency-filter

vue-currency-filter is a package that provides us with filters for formatting currencies.

To use it, first we install it by running:

npm install vue-currency-filter

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueCurrencyFilter from "vue-currency-filter";
Vue.use(VueCurrencyFilter, {
  symbol: "$",
  thousandsSeparator: ".",
  fractionCount: 2,
  fractionSeparator: ",",
  symbolPosition: "front",
  symbolSpacing: true
});
Vue.config.productionTip = false;

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

App.vue

<template>
  <div id="app">{{ 3000 | currency}}</div>
</template>

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

symbol is the currency symbol,

thousandsSeparator is the thousands separator,

fractionCount is the number of decimal places.

fractionSeparator is the separator for decimal digits.

symbolPosition is where we put the currency symbol.

symbolSpacing is the spacing of the currency symbol.

In the template, we use the currency filter to format the number.

vue-textarea-autosize

vue-textarea-autosize is a text area component that changes height automatically.

To install it, we run:

npm i vue-textarea-autosize

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import TextareaAutosize from "vue-textarea-autosize";

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

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

App.vue

<template>
  <div id="app">
    <textarea-autosize
      placeholder="text"
      ref="textarea"
      v-model="value"
      :min-height="30"
      :max-height="350"
    />
  </div>
</template>

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

to use it.

We have the placeholder prop to set the placeholder.

ref is the ref we can use to call DOM methods.

min-height and max-height adjust the height of the text area.

We can write:

<template>
  <div id="app">
    <textarea-autosize
      placeholder="text"
      ref="textarea"
      v-model="value"
      :min-height="30"
      :max-height="350"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: ""
    };
  },
  mounted() {
    this.$refs.textarea.$el.focus();
  }
};
</script>

to focus the text area.

To add auto-sizing, we can use the autosize prop:

<template>
  <div id="app">
    <textarea-autosize
      autosize
      placeholder="text"
      ref="textarea"
      v-model="value"
      :min-height="30"
      :max-height="350"
    />
  </div>
</template>

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

vue-clipboard

vue-clipboard lets us copy or cut text to the clipboard with the bundled directive.

To install it, we run:

npm i vue-clipboards

Then we can write:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueClipboards from "vue-clipboards";

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

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

App.vue

<template>
  <div id="app">
    <button v-clipboard="copyData">Copy</button>
  </div>
</template>

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

We register the VueClipboards plugin.

Then we use the v-clipboards directive to let us copy the data when the button is pressed.

vue-masonry

vue-masonry is a Vue plugin that lets us add a masonry effect to our Vue app easily.

We can display pictures in a grid like Google or Flickr.

To use it, we install it by writing:

npm i vue-masonry

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import { VueMasonryPlugin } from "vue-masonry";

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

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

App.vue

<template>
  <div id="app">
    <div v-masonry="containerId" transition-duration="0.3s" item-selector=".item">
      <div v-masonry-tile class="item" v-for="n in 30" :key="n">
        <img src="http://placekitten.com/200/200">
      </div>
    </div>
  </div>
</template>

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

We register the plugin.

Then we use the v-masonry and v-masonry-tile directive to apply the masonry effect to the photos.

transition-duration is the length of the transition when resizing the grid.

Conclusion

vue-currency-filter is a plugin that lets us format currencies.

vue-textarea-autosize is a text area that can resize according to the text.

vue-clipboard lets us copy data to the clipboard

vue-masonry is a photo masonry grid.