Single-page applications have numerous advantages?—?speed, great UX, and, with respect to creating for Drupal, the full power over the markup. There are an expanding number of destinations utilizing SPA; there are an ever increasing number of devices that streamline the way toward creating complex SPA. On the off chance that you read our articles (and if not, you should), you've most likely found out about a youthful responsive structure called Vue.js, and how you can utilize it in Drupal. 

We will make a customer side use of a straightforward blog. This application will demonstrate a rundown all things considered, and the full content of the article. All progressions will happen without reloading a page. With the case of this application, you will become more acquainted with how to get information in Vue, how to make a switch, and you will find out about an extremely fascinating concept?—?Vue single record parts. 


Since we are just worried about the customer, we will utilize the benefit which gives the phony online REST API. In the event that you need to utilize Drupal as a backend (jeez, it is the Drupal site, obviously, you do), we've effectively expounded on the most proficient method to sort out a RESTful server with Drupal 8. Check the articles on RESTful in the square Useful connections. 

Customer side 


For kicking off another task, I exceedingly suggest vue-cli. Utilizing this you can begin the task with a portion of the official Vue venture formats, or one of the a considerable lot of the open source layouts, and, obviously, you can make your very own one and utilize it anyplace. 

Along these lines, as a matter of first importance, we have to introduce vue-cli as a worldwide bundle: 

At that point introduce venture with the picked layout. For this venture, I utilized webpack-straightforward. 

At that point go to the vue-spa envelope and run npm introduce in the terminal. Subsequent to introducing every one of the bundles, we can run our application in the improvement mode. 

This will consequently dispatch our venture on the webpack dev server. In the program, we can see our basic Vue application. Obviously, it doesn't look how we need.. however. To proceed with the work I recommend first to acquaint yourself with the structure of our layout. 

Webpack-basic layout 

Inside the webpack-basic layout we have the accompanying structure: 

There is an index.html record with a straightforward HTML markup incorporating just the component with identifier "application" in a body. It will be supplanted by a Vue-created DOM. That is the motivation behind why you ought not utilize the tag <body> as a root component. 

In the src index, we have the main.js document which is the section point for webpack. The Vue segments are transported in here. Additionally, we have a root Vue occasion which has two properties for the present. The property 'el' furnishes the Vue case with a current DOM component to mount on. Furthermore, another is a render work which creates DOM from App.vue. 

All in all, this is all we have to think about the structure of the webpack-basic format. Not all that awful, is it? The fundamental piece of our application will be coded in App.vue. The .vue augmentation demonstrates that this record is a solitary document vue part. It is one of the Vue's highlights, how about we become more acquainted with it better. 

Develop Your Website With Vue.js

Single File Components 

Every *.vue document comprises of three sorts of squares: <template>, <script> and discretionary <style>. As its consequence, we can partition the task into inexactly coupled segments. Inside a segment, its format, rationales, and styles are inalienably coupled, and gathering them really makes the segment more durable and viable. So now we are prepared to make our Vue Blog. 

Making the application 

We have a header with the name of our blog at the highest point of the page. On the left side, we have a settled sidebar in which we will show the headings of our articles?—?it will be something like a chapter by chapter list. Whatever remains of the page will be involved by a dynamic square in which the article itself will be shown. 

Stage 1 

Expel every single superfluous line from App.vue, and make a layout as per our necessities. 


<div id="app"> 


<h1>Vue.js SPA</h1> 



<aside class="sidebar"> 


<div class="content"> 





Next, we will make a Vue case with the information property that we will put in the exhibit with our posts. For the time being it's vacant, yet soon we will put the information got from our server inside the exhibit. 

When watched, you can never again add receptive properties to the root information protest. It is thusly prescribed to announce all root-level receptive properties forthright before making the Vue case. 


trade default { 

information () { 

return { 

posts: [] 


Likewise, I've added a few styles to improve our application look. 

The application code lives on the Simply clone the vault and switch the branch by the progression number to pursue the application creation well ordered, for instance: 

As of now we have literally nothing to show in our route bar, so how about we get the information from our server. To do this I picked axios, an extremely simple to-utilize HTTP customer. You can likewise utilize some other advantageous path for you like a Vue-asset or local get or even jQuery Ajax. 

How to build a simple Vue CLI plugin

Stage 2 

Introduce the axios 

At that point import it into a segment App and make a strategy getAllPosts() which we will make a demand to the Drupal server and set it to the property post. Call the technique in the snare made(), which will be called after the Vue case is made and information perception has been set up. 

import axios from 'axios' 

send out default { 

information () { 

return { 

posts: invalid, 

endpoint: '', 


made() { 



strategies: { 

getAllPosts() { 


.then(response => { 

this.posts =; 


.catch(error => { 

console.log('- - blunder - '); 



Also, now show every one of the headings of articles in the sidebar. 

<aside class="sidebar"> 

<div v-for="post in posts"> 




So far we have shown the names of posts, yet we can not see the full posts. Presently I will show the full post in the substance segment as per the picked title in the sidebar. In the meantime, I need each article to be accessible at its special location. 

Stage 3 

I will utilize the official Vue library vue-switch to actualize this. As it ought to be obvious from the name, this library permits designing directing for our application. 

Introduce the bundle: 

$ npm install?—?save-dev vue-switch 

To design the switch, come back to the main.js document. Here we will characterize the settings of our switch and add it to the Vue case. 

import Vue from 'vue' 

import Router from 'vue-switch' 

import App from './App.vue' 

import Post from './segments/Post.vue' 

import Hello from './segments/Hello.vue' 


const switch = new Router({ 

courses: [ 

way: '/', 


segment: Hello, 


way: '/post/:id', 


segment: Post, 

props: genuine, 



new Vue({ 

el: '#app', 

render: h => h(App), 



In the course settings, we indicate which part ought to be rendered on a predetermined way. Since the main part Post.vue will be in charge of rendering of each post, we don't need to set the way for each post, all we require is to set a dynamic way. 

What is Vuejs?

way: '/post/:id' 

This way has a dynamic portion :id which decides the points of interest of our post. We have the entrance to this portion in part Post by means of this.$ Be that as it may, utilizing $route in our segment makes a tight coupling with the course which confines the adaptability of the part as it must be utilized on specific URLs. Rather than this we can utilize the alternative props and set it to genuine. From that point onward, the $route.params is set as the segment Post props. 

Since we have a switch made we can come back to our application and add a couple of more lines to the layout. 


<aside class="sidebar"> 


v-for="post in posts" 

dynamic class="is-dynamic" 


:to="{ name: 'post', params: { id: } }"> 


</switch link> 


<div class="content"> 

<router-view></switch view> 



Here we have two segments of vue-switch: <route>r-connect and <router-view>. The first is the segment for empowering client route in a switch empowered application. The second segment is an utilitarian segment that renders a coordinated part for the given way. 

Stage 4 

We should go to the Post.vue document, which we will make a straightforward layout in: 

<template lang="html"> 

<div class="post" v-if="post"> 

<h1 class="post__title"></h1> 

<p class="post__body"></p> 

<p class="post__id"></p> 



At that point we have to set Vue case settings for this segment. Here, everything will be fundamentally the same as the settings for showing all posts. Proclaim the choice props with variable id, which will get the quantity of our post. Next, characterize the information protest: 

import axios from 'axios'; 

send out default { 

props: ['id'], 

information() { 

return { 

post: invalid, 

endpoint: '', 

At that point make the strategy getPost() which will get just a single post by an identifier and call it in the made() snare.

techniques: { 

getPost(id) { 

axios(this.endpoint + id) 

.then(response => { = 


.get( mistake => { 




made() { 



Nearly done. On the off chance that we run the application now, we'll see that despite the fact that the URL transforms, we just observe the post that was rendered first. Since the segment rendering the post does not change, Vue does not re-render it trying to spare assets. This implies the lifecycle snares are never executed. 

To settle this we simply need to set a watcher for the $route protest. 

watch: { 

'$route'() { 


Presently it works precisely as it should! 


We manufactured the basic single page application with Vue in four stages. We knew how simple to begin your task with vue-cli. We made sense of the idea of Vue single-document segments which make your undertaking more adaptable and versatile. We figured out how to bring information from outer API utilizing axios. Furthermore, we perceived how to arrange directing with the vue-switch. To get a creation adaptation of this application simply run npm run work in your terminal. On the off chance that you have any inquiries, don't falter to get in touch with us.

What you pick in 2018 : ReactJS vs AngularJS vs VueJS
Why every beginner front-end developer should know publish-subscribe pattern?
Writing an Amazing Code Review Checklist