1563934931
We’ll be using Pusher’s pub/sub pattern to get realtime updates and Vue.js for creating the user interface.
To follow this tutorial a basic understanding of Vue and Node.js is required. Please ensure that you have at least Node version 6>= installed before you begin.
We’ll be using these tools to build our application:
Here’s a demo of the final product:
To get started, we will use the vue-cli to bootstrap our application. First, we’ll install the CLI by running npm install -g @vue/cli
in a terminal.
To create a Vuejs project using the CLI, we’ll run the following command:
vue create vue-eventapp
After running this command, you will be asked by the CLI to pick a preset. Please select the default preset.
Note: the @vue/cli 3.0 is still in beta and should not be used in production.
Next, run the following commands in the root folder of the project to install dependencies.
// install depencies required to build the server
npm install express body-parser dotenv pusher
// front-end dependencies
npm install pusher-js vue-fullcalendar@latest date-fns vuejs-datepicker
Start the app dev server by running npm run serve
in a terminal in the root folder of your project.
A browser tab should open on http://localhost:8080. The screenshot below should be similar to what you see in your browser:
We’ll build our server using Express. Express is a fast, unopinionated, minimalist web framework for Node.js.
Create a file called server.js
in the root of the project and update it with the code snippet below
// server.js
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const Pusher = require('pusher');
const app = express();
const port = process.env.PORT || 4000;
const pusher = new Pusher({
appId: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_KEY,
secret: process.env.PUSHER_SECRET,
cluster: process.env.PUSHER_CLUSTER,
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
next();
});
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});
The calls to our endpoint will be coming in from a different origin. Therefore, we need to make sure we include the CORS headers (Access-Control-Allow-Origin
). If you are unfamiliar with the concept of CORS headers, you can find more information here.
Create a Pusher account and a new Pusher Channels app if you haven’t done so yet and get your appId
, key
and secret
.
Create a file in the root folder of the project and name it .env
. Copy the following snippet into the .env
file and ensure to replace the placeholder values with your Pusher credentials.
// .env
// Replace the placeholder values with your actual pusher credentials
PUSHER_APP_ID=PUSHER_APP_ID
PUSHER_KEY=PUSHER_KEY
PUSHER_SECRET=PUSHER_SECRET
PUSHER_CLUSTER=PUSHER_CLUSTER
We’ll make use of the dotenv
library to load the variables contained in the .env
file into the Node environment. The dotenv
library should be initialized as early as possible in the application.
Let’s create a post route named schedule
, our application will send requests to this route when a user attempts to schedule events.
// server.js
require('dotenv').config();
...
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
...
});
app.post('/schedule', (req, res) => {
const {body} = req;
const data = {
...body,
};
pusher.trigger('schedule', 'new-event', data);
res.json(data);
});
...
trigger
method which takes the trigger identifier(schedule
), an event name (new-event
), and a payload.Start the server by running node server
in a terminal in the root folder of your project.
We’ll be creating a component(Calendar
), this component will display our calendar with the events scheduled by a user.
Create a file called Calendar.vue
in the src/components
folder of your project. Open the file and copy the code below into it:
// src/components/Calendar.vue
<template>
<full-calendar :events="events" />
</template>
<script>
import FullCalendar from 'vue-fullcalendar';
export default {
name: 'Calendar',
props: ['events'],
components: {
FullCalendar
}
}
</script>
<style>
.red {
background: rgb(235, 77, 77) !important;
color: whitesmoke !important;
}
.blue {
background: rgb(59, 59, 163) !important;
color: whitesmoke !important;
}
.orange {
background: orange !important;
color: white !important;
}
.green {
background: rgb(49, 155, 49) !important;
color: white !important;
}
.blue,
.orange,
.red,
.green {
font-size: 13px;
font-weight: 500;
text-transform: capitalize;
}
.event-item {
padding: 2px 0 2px 4px !important;
}
</style>
Our component will make use of the Vue-fullcalendar library. The library provides a full-calendar
component. Our component will receive an events
prop, a list of events to be bound to the full-calendar
component.
Also, we’ve added a few styles to the style
section of the component. These styles will help theme the events that will be bound to the calendar. Later in the tutorial, we’ll make use of these styles.
Now that the we’ve set up the calendar component, let’s create an EventForm
component that will be used for scheduling new events.
Create a file EventForm.vue
in the src/components
folder. Copy the following into the file. We’ll break it down into three snippets, the template
snippet, followed by the script
and finally the style
snippet.
The template will hold the form element that will handle creation of new events.
// /src/components/EventForm.vue
<template>
<form @submit.prevent="handleSubmit">
<div class="input-holder">
<input type="text" placeholder="Event title" v-model="event.title"/>
</div>
<div class="input-holder">
<date-picker :placeholder="'Start date'" v-model="event.start" />
</div>
<div class="input-holder">
<date-picker :placeholder="'End date'" v-model="event.end"/>
</div>
<div class="input-holder">
<textarea placeholder="Event description" rows="4" v-model="event.data.description" ></textarea>
</div>
<div class="input-holder">
<color-picker @colorPicked="selectColor" :color="event.cssClass" />
</div>
<div class="input-holder">
<button type="submit">Schedule</button>
</div>
</form>
</template>
In the template, we made use of the date-picker
component, Vuejs-datepicker. This component will handle start
and stop
date selection for our events. Also, we’ll be able to theme our events using a color-picker
. We haven’t gone about creating the color-picker
component but that’s coming soon.
We’ll handle all the functionality of our component in the script section. Update the EventForm.vue
file to include the script section.
// src/components/EventForm.vue
<template>
...
</template>
<script>
import DatePicker from 'vuejs-datepicker';
import format from 'date-fns/format';
import ColorPicker from './ColorPicker';
export default {
name: 'EventForm',
data(){
return {
event: {
title: '',
start: '',
end: '',
cssClass: '',
data: {
description: ''
}
}
}
},
methods: {
async handleSubmit(){
const start = format(this.event.start, 'YYYY-MM-DD');
const end = format(this.event.end, 'YYYY-MM-DD');
const event = {
...this.event,
start,
end
}
const req = await fetch('http://localhost:4000/schedule', {
method: 'POST',
body: JSON.stringify(event),
headers: {
'content-type': 'application/json'
}
});
const res = await req.json();
this.resetValues();
},
selectColor(color){
this.event = {
...this.event,
cssClass: color
}
},
resetValues(){
this.event = {
title: '',
start: '',
end: '',
cssClass: '',
data: {
description: ''
}
}
}
},
components: {
DatePicker,
ColorPicker
}
}
</script>
In our scripts section, we have one data
property, event
, this will hold all the data needed to schedule an event. The methods
property has three methods. The handleSubmit
method uses the date-fns library to format the start
and end
dates and then sends the data to the server to schedule an event. When a response is returned, the data in the response is emitted to the parent component. The resetvalues
method resets the values to their initial state.
The selectColor
method will be bound to the colorPicked
event emitted by the color-picker
component. This method is triggered whenever a color is selected.
Update the component with the following styles:
// src/components/EventForm.vue
<template>
...
</template>
<script>
...
</script>
<style>
form {
display: flex;
flex-direction: column;
margin-left: 30px;
}
.input-holder {
margin: 10px 0;
display: flex;
justify-content: flex-start;
}
.vdp-datepicker {
width: 100%;
}
.vdp-datepicker > div > input {
width: 77%;
}
.input-holder > button {
justify-self: center;
padding: 12px 25px;
border-radius: 0;
text-transform: uppercase;
font-weight: 600;
background: orangered;
color: white;
border: none;
font-size: 14px;
letter-spacing: -0.1px;
cursor: pointer;
}
input,
textarea {
padding: 12px 15px;
border: 2px solid rgba(0, 0, 0, 0.2);
border-radius: 0;
width: 70%;
opacity: 0.8;
font-size: 15px;
font-weight: normal;
}
input:focus,
textarea:focus,
button:focus {
border: 2px solid orangered;
outline: none;
box-shadow: 0 2px 3px 1px rgba(0, 0, 0, 0.2);
}
</style>
Next, let’s create the color-picker
component.
The color component will help us theme our event by letting us select a color that suits the event. Create a file named ColorPicker.vue
in the src/components/
directory and update it with the code below:
// src/components/ColorPicker.vue
<template>
<div class="picker-main">
<h4 class="header">Select event theme</h4>
<div class="color-picker">
<div class="color" v-for="(theme, index) in colors" :key="index" @click="selectColor(theme)" :class="{selected: color === theme, [theme]: theme}"></div>
</div>
</div>
</template>
<script>
export default {
name: 'ColorPicker',
props: ['color'],
data(){
return {
colors: ['red', 'green', 'blue', 'orange']
}
},
methods: {
selectColor(color){
this.$emit('colorPicked', color);
}
}
}
</script>
<style scoped>
.picker-main {
width: 55%;
}
.header {
font-size: 14px;
text-transform: uppercase;
color: orangered;
letter-spacing: 0.5px;
margin: 0 0 6px;
text-align: left;
}
.color-picker {
display: flex;
justify-content: space-around;
}
.color-picker > .color {
width: 40px;
height: 40px;
border-radius: 50%;
border: 1.5px solid whitesmoke;
cursor: pointer;
}
.color.selected{
box-shadow: 0 2px 3px 1px rgba(0, 0, 0, 0.2);
border: 3px solid rgba(0, 0, 0, 0.4);
}
.color.red {
background: rgb(235, 77, 77);
}
.color.blue {
background: rgb(59, 59, 163);
}
.color.orange {
background: orange;
}
.color.green {
background: rgb(49, 155, 49);
}
</style>
In the template section, we loop through an array of colors
, creating a clickable element that emits a color
when clicked. The component takes a prop color
from the parent component.
Now that we’ve built out the components to be used for our application, let’s render them in the App
component to create a usable application. Open the App.vue
file and update it to look like the snippet below:
// src/App.vue
<template>
<div id="app">
<div class="main">
<div class="calendar-holder">
<calendar :events="events" />
</div>
<div class="form-holder">
<h3>Schedule an event</h3>
<event-form />
</div>
</div>
</div>
</template>
<script>
import Calendar from './components/Calendar.vue'
import EventForm from './components/EventForm.vue'
import Pusher from 'pusher-js';
export default {
name: 'app',
components: {
Calendar,
EventForm
},
data(){
return {
events: [{
title : 'event1',
start : '2018-07-09',
cssClass : 'blue',
YOUR_DATA : {}
},
{
title : 'event2',
start : '2018-07-10',
end : '2018-07-13',
cssClass : ['orange']
}]
}
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.main {
display: flex;
align-items: center;
}
.calendar-holder {
width: 65%;
}
.form-holder {
width: 35%;
}
.form-holder > h3 {
color: orangered;
text-transform: uppercase;
font-size: 16px;
text-align: left;
margin-left: 30px;
margin-bottom: 10px;
}
</style>
We’ve populated the data
property with a list of events. There is a method handleNewEvent
, this method is bound to the event-form
component. It appends the new event emitted from the event-form
component to the list of events.
You can now check out the current look of the application by visiting http://localhost:8080. Make sure both the vue dev server (yarn serve
) and the server (node server
) are running in separate terminals in the root folder of your project.
Our application will update in realtime whenever there’s a new event added. We’ll be using Pusher’s pub/sub pattern to enable this functionality in our application.
We’ll update the App
component to include the created
lifecycle. It’s in this lifecycle we’ll initialise Pusher and listen for new events. Open the App.vue
file and update it to match the snippet below:
// /src/App.vue
<template>
...
</template>
<script>
import Calendar from './components/Calendar.vue'
import EventForm from './components/EventForm.vue'
import Pusher from 'pusher-js';
export default {
name: 'app',
components: {
...
},
data(){
...
},
created(){
const pusher = new Pusher('PUSHER_KEY', {
cluster: 'PUSHER_CLUSTER',
encrypted: true,
});
const channel = pusher.subscribe('schedule');
channel.bind('new-event', (data) => {
this.events = [
...this.events,
data
];
})
}
}
</script>
<style>
...
</style>
Note: ensure you replace the
PUSHER_KEY
andPUSHER_CLUSTER
placeholder strings with your actual credentials.
In the created
lifecycle, we initialized Pusher, subscribed to the schedule
channel and listened for the new-event
event. In the callback, we appended the data returned from the event to the list of events.
Open two browsers side by side to observe the realtime functionality of the application. Events scheduled on one browser are picked up by the other browser. Here’s a screenshot of two browsers side by side using the application:
Note: Ensure both the server and the dev server are up by running
npm run serve
andnode server
on separate terminal sessions.
We’ve created an event scheduling application using Vue.js, using Pusher to provide realtime functionality. You can think up new ideas to extend the application. It’ll be fun to see what you come up with. The source code for this tutorial is available on GitHub here.
Further reading:
☞ Get Value From Selected Dropdown in Vue.js
☞ Building Frontend Using Vuetify
☞ Using Nuxt generate for building static web applications
☞ Vue.js Get String Length Example
#vue-js #javascript
1640869030
Hi , Take a look at Syncfusion Vue Calendar . A lightweight and easily configurable calendar component. Please find the Demo.
Note: I work for Syncfusion
1600583123
In this article, we are going to list out the most popular websites using Vue JS as their frontend framework.
Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.
This framework was created by Evan You and still it is maintained by his private team members. Vue is of course an open-source framework which is based on MVVM concept (Model-view view-Model) and used extensively in building sublime user-interfaces and also considered a prime choice for developing single-page heavy applications.
Released in February 2014, Vue JS has gained 64,828 stars on Github, making it very popular in recent times.
Evan used Angular JS on many operations while working for Google and integrated many features in Vue to cover the flaws of Angular.
“I figured, what if I could just extract the part that I really liked about Angular and build something really lightweight." - Evan You
#vuejs #vue #vue-with-laravel #vue-top-story #vue-3 #build-vue-frontend #vue-in-laravel #vue.js
1623650417
Overview
The Vue Scheduler, or event calendar, is a fully featured event calendar component that helps users manage their time efficiently. It facilitates easy resource scheduling and the rescheduling of events or appointments through editor pop-ups, drag and drop, and resizing actions.
#vue #scheduler #event calendar #web-development #ui-components
1578061020
Icons are the vital element of the user interface of the product enabling successful and effective interaction with it. In this article, I will collect 10 Vue icon component to bring more interactivity, better UI design to your Vue application.
A clean and simple Vue wrapper for SweetAlert’s fantastic status icons. This wrapper is intended for users who are interested in just the icons. For the standard SweetAlert modal with all of its bells and whistles, you should probably use Vue-SweetAlert 2
Demo: https://vue-sweetalert-icons.netlify.com/
Download: https://github.com/JorgenVatle/vue-sweetalert-icons/archive/master.zip
Create 2-state, SVG-powered animated icons.
Demo: https://codesandbox.io/s/6v20q76xwr
Download: https://github.com/kai-oswald/vue-svg-transition/archive/master.zip
Awesome SVG icon component for Vue.js, with built-in Font Awesome icons.
Demo: https://justineo.github.io/vue-awesome/demo/
Download: https://github.com/Justineo/vue-awesome/archive/master.zip
Transitioning Result Icon for Vue.js
A scalable result icon (SVG) that transitions the state change, that is the SVG shape change is transitioned as well as the color. Demonstration can be found here.
A transitioning (color and SVG) result icon (error or success) for Vue.
Demo: https://transitioning-result-icon.dexmo-hq.com/
Download: https://github.com/dexmo007/vue-transitioning-result-icon/archive/master.zip
Easily add Zondicon icons to your vue web project.
Demo: http://www.zondicons.com/icons.html
Download: https://github.com/TerryMooreII/vue-zondicons/archive/master.zip
Vicon is an simple iconfont componenet for vue.
iconfont
iconfont is a Vector Icon Management & Communication Platform made by Alimama MUX.
Download: https://github.com/Lt0/vicon/archive/master.zip
A tool to create svg icon components. (vue 2.x)
Demo: https://mmf-fe.github.io/vue-svgicon/v3/
Download: https://github.com/MMF-FE/vue-svgicon/archive/master.zip
This library is a collection of Vue single-file components to render Material Design Icons, sourced from the MaterialDesign project. It also includes some CSS that helps make the scaling of the icons a little easier.
Demo: https://gitlab.com/robcresswell/vue-material-design-icons
Download: https://gitlab.com/robcresswell/vue-material-design-icons/tree/master
Vue Icon Set Components from Ionic Team
Design Icons, sourced from the Ionicons project.
Demo: https://mazipan.github.io/vue-ionicons/
Download: https://github.com/mazipan/vue-ionicons/archive/master.zip
Dead easy, Google Material Icons for Vue.
This package’s aim is to get icons into your Vue.js project as quick as possible, at the cost of all the bells and whistles.
Demo: https://material.io/resources/icons/?style=baseline
Download: https://github.com/paulcollett/vue-ico/archive/master.zip
I hope you like them!
#vue #vue-icon #icon-component #vue-js #vue-app
1578472348
Vue highlight is often used to highlight text and syntax. Here are the 7 Vue highlight components I’ve collected.
Vue3 Snippets, This extension adds Vue3 Code Snippets into Visual Studio Code.
Vim syntax and indent plugin for vue files
Vue directive for highlight multiple istances of a word.
Beautiful code syntax highlighting as Vue.js component.
A dead simple code editor with syntax highlighting and line numbers. 7kb/gz
Features
A simple port from react-highlight-words
Vue component to highlight words within a larger body of text.
Vue component for highlight multiple istances of a word.
Thank for read!
#vue-highlight #vue #vue-highlight-component #highlight-vue
1578332107
Markdown is a way to style text on the web. You control the display of the document; formatting words as bold or italic, adding images, and creating lists are just a few of the things we can do with Markdown.
The 10 Vue markdown components below will give you a clear view.
Use showdown as a Vue component.
A markdown editor using codemirror and previewer using showdown for Vue.js.
The vue lib for markdown-it.
perfect-markdown is a markdown editor based on Vue & markdown-it. The core is inspired by the implementation of mavonEditor, so perfect-markdown has almost all of the functions of mavonEditor. What’s more, perfect-markdown also extends some features based on mavonEditor.
Vue.js Markdown Editor component.
Markdown to Vue component loader for Webpack.
fo-markdown-note is a Vue.js component that provides a simple Markdown editor that can be included in your Vue.js project.
fo-markdown-note is a thin Vue.js wrapper around the SimpleMDE Markdown editor JavaScript control.
Markdown Editor component for Vue.js. Support both vue1.0 & vue2.0
A nice vue.js markdown editor. Support WYSIWYG editing mode, reading mode and so on.
A Powerful and Highspeed Markdown Parser for Vue.
Thank for read!
#vue-markdown #vue-js #vue-markdown-component #vue