Categories
JavaScript Vue

Add a Timeline Chart to a Vue App

We can add a timeline chart to a Vue app with the vue-cute-timeline package.

vue-cute-timeline is a timeline component that we can use with Vue apps.

It displays a vertical timeline on our screen.

To install it, we run:

npm i vue-cute-timeline

Then we can use it by writing:

<template>
  <div id="app">
    <timeline>
      <timeline-title>title</timeline-title>
      <timeline-item bg-color="#9dd8e0">foo</timeline-item>
      <timeline-item :hollow="true">bar</timeline-item>
    </timeline>
  </div>
</template>
 
<script>
import { Timeline, TimelineItem, TimelineTitle } from "vue-cute-timeline";
export default {
  components: {
    Timeline,
    TimelineItem,
    TimelineTitle
  }
};
</script>

We just import the timeline components.

Then we get a vertical timeline with the content between the tags.

bg-color has a background color.

hollow makes the dot hollow.

vue-cute-timeline lets us add a timeline to our app easily.

Categories
Book Reviews Vue

Best Books for Learning Vue

Vue is an easy to learn framework.

However, online documentation often don’t cover everything that we need to master the framework.

Therefore, we can get some help with a few books.

Here are some good books that we can use to learn Vue.

Testing Vue.js Applications

This book covers everything we need to know about testing Vue apps, from creating the first test to testing Vuex and server side rendering.

It’s a very comprehensive book that goes through testing everything that we can think of in a Vue app.

This book provides us with many examples and provides clear explanations of everything that it covers.

Vue.js in Action

This book provides us with a gentle introduction of Vue.

It introduces us from the most basic concepts to concepts that let us build a whole app.

This book goes from introducing us to the most basic part of a Vue app to animations to Vuex and Vue Router.

It’s pretty much the guide that will let us master Vue in no time.

Practical examples are sprinkled throughout the book to help us understand the concepts outlined.

Fullstack Vue: The Complete Guide to Vue.js

Fullstack Vue: The Complete Guide to Vue.js is a book that introduces us to Vue.

In addition, it goes through examples that integrates with other apps like a back end app to provide us with an introduction to integrate Vue apps with other modules to build a complete system.

The book has lots of runnable code to let us poke around with to help us learn.

It covers the latest features.

It covers everything from the basics, to communicating with server APIs, and testing.

These 3 books provide us with a useful guide on how to build Vue apps from start to finish.

We can master it in no time.

Categories
JavaScript Vue

Add a WYSIWYG Editor into a Vue App with the vue-wysiwyg NPM Package

We can add a WYSIWYG text editor with the vue-wysiwyg package.

First, we install it by running:

npm i vue-wysiwyg

Next, we register the component and import the CSS by writing:

import Vue from "vue";
import App from "./App.vue";
import wysiwyg from "vue-wysiwyg";
import "vue-wysiwyg/dist/vueWysiwyg.css";

Vue.use(wysiwyg, {});
Vue.config.productionTip = false;

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

Then we can use the wysiwyg component to add the rich text editor to our app by writing:

<template>
  <div>
    <wysiwyg v-model="content"/>
    <div v-html="content"></div>
  </div>
</template>

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

We just bind whatever is entered with v-model.

The entered content will be converted to HTML.

So, we can display the content with v-html.

It also takes an object as a second argument to Vue.use to set the options for the text editor.

This argument is optional.

For instance, we can write:

import Vue from "vue";
import App from "./App.vue";
import wysiwyg from "vue-wysiwyg";
import "vue-wysiwyg/dist/vueWysiwyg.css";

Vue.use(wysiwyg, {
  hideModules: { underline: true },
  iconOverrides: { bold: `<span>bold</span>` },
  image: {
    uploadURL: "/api/myEndpoint",
    dropzoneOptions: {}
  },
  maxHeight: "500px"
});
Vue.config.productionTip = false;

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

Then we can hide modules with hideModules, iconOverrides lets us change the icons.

image lets us upload an image via a URL.

maxHeight changes the maximum height.

vue-wysiwyg is a very flexible text WYSIWYG text editor for Vuejs.

It has many options that we can add to change the appearance of the editor to what we want.

It outputs HTML so we can use the created data anywhere.

Categories
JavaScript Vue

Add a Vuejs Range Slider with vue-slider-component

We can add a range slider in a Vuejs app with the vue-slider-component.

To use it, we install it by running:

npm i vue-slider-component

Then we can use it after registering it:

<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 import the component and the styles and then register the component.

Then we add the vue-slider component to add the range slider to our component.

Now we see a slider displayed on the screen.

The min value is 0 and max is 100 by default.

It has many other options.

We can set the interval prop to change the interval.

We can add the mark prop to display numbers on the range slider.

Also, we can add the tooltip prop to display a tooltip with the currently selected value.

For instance, we can write:

<template>
  <div>
    <vue-slider v-model="value" tooltip="always"/>
    <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>

to show the tooltip.

The min and max values can be changed with the minRange and maxRange props respectively.

The fixed prop keeps the distance between 2 sliders fixed.

For instance, we can write:

<template>
  <div>
    <vue-slider v-model="value" :minRange="20" :maxRange="50"/>
    <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, 100]
    };
  }
};
</script>

We have an array for value to enable range mode.

This will make the range slider show 2 slider handles instead of one.

Then we can set the min and max values which will be the positions of 2 sliders.

The vue-slider-component is a range slider that has many options.

We can select a single number or a range of numbers.

The interval can be changed and we can display numbers on the range slider or the tooltip as we wish.

Categories
JavaScript Vue

Add a Color Picker to a Vuejs App

To add a color picker to a Vuejs app, we can use the vue-color package.

To install it, we run:

npm install vue-color

Then we can use it by writing:

<template>
  <div>
    <photoshop-picker v-model="colors"/>
    <p>{{colors}}</p>
  </div>
</template>

<script>
import { Photoshop } from "vue-color";

export default {
  data() {
    return {
      colors: {}
    };
  },
  components: {
    "photoshop-picker": Photoshop
  }
};
</script>

We just register the component and bind the selected value to the colors state.

The Photoshop-style color picker looks like the color picker in Photoshop.

Other styles include the Material style, compact style, swatches, slider, and Sketch-style.

They can be imported the same way.

The selected color will have several properties with color values.

For example, we may get something like:

{ "hsl": { "h": 0, "s": 0.26726650614624253, "l": 0.27429116, "a": 1 }, "hex": "#593333", "hex8": "#593333FF", "rgba": { "r": 89, "g": 51, "b": 51, "a": 1 }, "hsv": { "h": 0, "s": 0.42179999999999995, "v": 0.34759999999999996, "a": 1 }, "oldHue": 0, "source": "hsva", "a": 1 }

for colors.

We get the RGB, hex, and HSL values all in one object.

The vue-color package lets us add a color picker to our Vuejs app easily.

It’s easy to use and comes in many styles.