Introduction.
Vue is one of the popular modern JavaScript Front End Development Frameworks used with other tools in the JavaScript ecosystem to create apps for various environments and platforms such as web, mobile, and cross-platform desktop apps. This article will explore the use of vue to create a web application for an e-library based on e-library backend api repository found at https://github.com/barakaben/library_api.git or https://bitbucket.org/barakaben/library_api.git
Thanks for reading! Subscribe for free to receive new posts and support my work.
Requirements
In order to successfully accomplish the tasks of this development project, You will be required to essentially fulfill the followings requirements;
Have a working Linux/Unix OS based computer/machines.
NVM/Node.js installation in 1 above
Reliable Internet connection
Design
Our e-library app will consist of two main pages;
Paginated List of Books Available in an e-library
Book Detail page for each specific instance of book held in the e-library repository
The two pages above will make use of about three components those being;
- BookList component 2. BookDetail component 3. App component- that is built-in within the Vue framework and automatically provided to us during the app scaffolding process.
Dependency
Just as laid out in the introductory part of this article that our frontend e-library web app will depend on the backend api service whose code base is found at https://bitbucket.org/barakaben/library_api.git, it is critical that you should have your development/local computer properly set up to run this api service on it, in order to replicate the practical steps shown in this article locally.
However for quick implementation of this project we will use an online version of the backend api found at the following link:
https://barakabennie.pythonanywhere.com/api/v1. It is assumed the api service will be up and running at all times when the frontend app is in action.
Summary
In brief our app implementation journey will involve the following steps:
Preliminary Steps- These will include project folder creation and project initialization
Further Development Steps- These will include implementation of various features related to our app that are BookList component, “Download Pdf” button link, Details button link, BookDetail component, Web Page Title, Header and Footer features.
Steps
Preliminary Steps
We begin by creating the vue-projects folder in which our vue-elibrary app will reside. Turn on the command terminal and issue the command
mkdir vue-projects & cd $_
the above command once issued will create the named directory and switch path to it.
Initialize the vue-elibrary app project by issuing the following command from within the vue-projects folder.
npm init vite@latest
After issuing the above command follow the instruction that appears on the screen as listed below by performing the relevant action per each instruction.
Beginning by providing the 1.name project
type vue-elibrary to replace the default name as shown below
2. pick framework

using the the down and up arrows move to select vue as shown below
3.Pick variant

Choose TypeScript and press Enter to scaffold the Vue app as appears in the next picture.

Change path to the newly created project’s app folder by running
cd project-name
Be mindful to replace the project-name with the exact name as used in step 1 above which is vue-elibrary in this particular case. Therefore change directory is done by issuing the following command
cd vue-elibrary
as it appears in the previous picture.
Run the command `npm install `

Run the command npm run dev to start the development server and serve the app locally.
Visit: http://localhost:5173 using your favorite browser app installed on your computer.
Further Development Steps
9.Implementing Book Listing feature
(i). Create a BookList.vue component in the src/components folder by running the following command
touch src/components/BookList.vue in the vue-elibrary root folder.
(ii). Open the BookList.vue file in code editor like visual studio code from the command line
while in the app root folder path by running the
code src/components/BookList.vue command from within the vue-elibrary root folder which is the root folder for this app’s project just like shown below.
Note as we will be running several commands from now onward please take the ~/vue-projects/vue-elibrary as the base path for running this and coming commands except where stated otherwise.
Also Note that the word code was used in the previous command to open the named file, this is simply due to the fact that I am using the visual studio code editor on my development machine. In case you are using a different Editor program please be guided accordingly on how to invoke it from the command line and replace word code to the right one for your editor wherever applicable.
(iii). Edit the BookList.vue file so that it appears as shown below.
<template> <div class=”booksList” v-for=”ebook in books” key=”ebook.id” style=”display:inline-flex;margin:0.4rem;”> <div class=”book”> <div class=”picture”> <img :src=”ebook.cover_image” /> </div> <div class=”booklinks”> <button><a href=”#book.pdf”>Download Pdf</a></button> <button><a href=”#books/book.id”>Details</a></button> </div> </div> </div> <!--<pagination></pagination>--> </template> <script> export default { name:’BookList’, data() { return { books:[], totalBooks:0 } }, created() { this.showPage() }, methods: { showPage( pageNo = 1 ) { fetch(import.meta.env.VITE_API_URL+`?page=+${pageNo}`) .then(response=>response.json()) .then(json=>this.books=json.results); }, } } </script> Remember to save the changes by clicking the “Ctrl + S” buttons combination or otherwise to make those changes effective.
(iv). Open the App.vue file in the code editor by issuing the
code src/App.vue command, and edit it to integrate BookList.vue component and remove linkage to the HelloWorld.vue component as shown below.
<script setup lang=”ts”> //import HelloWorld from ‘./components/HelloWorld.vue’ import BookList from ‘./components/BookList.vue’; </script> <template> <div> </div> <BookList /> </template> <style scoped> .logo { height: 6em; padding: 1.5em; will-change: filter; transition: filter 300ms; } .logo:hover { filter: drop-shadow(0 0 2em #646cffaa); } .logo.vue:hover { filter: drop-shadow(0 0 2em #42b883aa); } </style> (v). Create the .env file by issuing the touch .env command
(vi). Open the .env file in the code editor by issuing the code .env command
(vii). Edit and save the .env file so that it appears as shown below
(viii). Reviewing the progress made so far by launching the development server via npm run dev command and visiting the localhost:5173 via browser app again, it should be as appears below if everything is okay.
- Create/implement the BookDetail.vue components by running the following commands.
(i). Run the command touch src/components/BookDetail.vue
(ii). Run code src/components/BookDetail.vue command to open visual studio code and edit the BookDetail.vue file so created so that it appears as shown below
<template> <div class=”book”> <div class=”title”> <h3>title: {{ ebook.title }} </h3> </div> <div class=”authors”> <h3>authors: {{ ebook.authors }} </h3> </div> <div class=”cover”> <img :src=”ebook.cover_image” /> </div> <div class=”publisher”> <h3>publisher: {{ ebook.publisher }} </h3> </div> <div class=”year”> <h3>year: {{ ebook.year }} </h3> </div> </div> </template> <script lang=”ts”> export default{ name:”BookDetail”, data(){ return{ ebook:{ id:”“, title:”“, authors:”“, cover_image:”“, publisher:”“, year:”“ } }; }, created(){ let id = this.$route.params.id; fetch(import.meta.env.VITE_API_URL+’ebooks/’+id). then(res=>res.json()). then(json=>this.ebook=json); } }; </script> - Implement Routing
To implement routing carry out the following steps
(i). Run the npm install vue-router@4 command
(ii). Run touch src/router.js command
(iii). Run code src/router.js command to open the router.js file and edit it so that it appears as shown below.
import { createRouter, createWebHistory } from “vue-router”; import BookList from “./components/BookList.vue”; import BookDetail from “./components/BookDetail.vue”; const routes=[ { path:”/books”, name:”books”, component:BookList }, { path:”/books/:id”, name:”bookdetails”, component:BookDetail }, { path:”/”, name:”books”, component:BookList} ]; const router = createRouter({ history:createWebHistory(), routes, }); export default router; (iv). Run code src/App.vue command to open the App.vue file
(v). Edit the src/App.vue file so that it appears as shown below
<script setup lang=”ts”> </script> <template> <router-view></router-view> </template> (vi). Open the main.ts file by running code src/main.ts command
(vii). Edit the src/main.ts file so that it appears as shown below.
import { createApp } from ‘vue’ import ‘./style.css’ import App from ‘./App.vue’ import router from “./router”; createApp(App).use(router).mount(’#app’) - Implement the download and detail button functionalities
(i). Open the src/components/BookList.vue by running
code src/components/BookList.vue command
(ii). Edit the src/components/BookList.vue by changing the “Download Pdf” button so that it appears as shown below.
<button><a :href=”ebook.pdf” target=”blank”>Download Pdf</a></button> (iii). Edit the src/components/BookList.vue again, this time changing the Details button so that it appears as shown below.
<button><router-link v-bind:to=”’/books/’+ebook.id”>Details</router-link></button> (iv). Check the functionality of “Download Pdf” button via browser, It should start the download process once clicked.
(v). Check the functionality of the “Details” button, It should cause the loading of specific book details once clicked.
- Implementing footer, header, banner, navigation, and title features
a. starting with footer and header, banner, and navigation.
(i). Open the src/App.vue file
(ii). edit the src/App.vue file so that it appears as shown below
<script setup lang=”ts”> </script> <template> <div class=”header” style=”background-color:silver;display:block;”> <div class=”logo”> <router-link to=”/”> <img src=”/vite.svg” alt=”logo” /> </router-link> </div> <ul class=”main-nav”> <li><router-link to=”/” style=”margin:0.5%;”>Home</router-link></li> <li><router-link to=”/books” style=”margin:0.5%;”>Books</router-link></li> </ul> </div> <router-view></router-view> <div class=”footer” style=”background-color:silver;vertical-align:center;”> <p><small>Copyright ©2024 Elibrary</small></p> </div> </template> <style> .header .main-nav li { list-style: none; display:inline-flex; margin:0.4rem; } .header .logo { float:left; max-width:100%; } .header { height:auto; } </style> b. moving on to the title feature.
(i). Open the index.html file by running code index.html command
(ii). Edit the index.html file by changing its title tag element so that it appears as shown below.
<title>Elibrary</title> c. Checking the progress made so far by turning up our local frontend development server and visiting http://localhost:5173 via the browser. The page should appear similar to the one shown below.
- Implement the the Pagination Feature
Pagination feature is very useful for simplification of large data access in piecewise fashion. Such access patterns help with user experience and site performance optimization as data obtained from the data layer is taken to the front end portion by portion which helps to minimize heavy memory and processor resources usage on both ends.
We will implement the pagination feature with the help of the PrimeVue ui components library. PrimeVue is a dedicated ui library to the Vue developers community. There exists several frontends’ libraries in the Vue Developers Community space, which really simplify one’s work by reusing the best written and tested front end ui components code in his/her own projects with ease. For more on primevue visit https://primevue.org
We will carry out the following three steps to implement the pagination feature with the BookList component.
- Install the primevue package in our app by running
npm install primevue command.
- Integrate the primevue by (i)importing PrimeVue and primevue.min.css and make use of those imports in src/main.ts as shown below.
import { createApp } from ‘vue’ import ‘./style.css’ import App from ‘./App.vue’ import PrimeVue from ‘primevue/config’ import Paginator from ‘primevue/paginator’ import ‘primevue/resources/primevue.min.css’ import router from ‘./router.js’ const app=createApp(App) app.component(’Paginator’,Paginator) app.use(PrimeVue) app.use(router) app.mount(’#app’) - Edit the showPage method under the methods section of the BookList.vue component so that it appears as shown below.
showPage( pageNo = 1 ) { fetch(import.meta.env.VITE_API_URL+`?page=+${pageNo}`) .then(response=>response.json()) .then(json=> { this.totalBooks=json.countthis.books=json.results }); } - Add the onPaginate(e) function to the methods section of BookList.vue file. Make sure that it appears as seen below.
onPaginate(e){ if((e.page)>0){ this.showPage(e.page) } } - Apply the Pagination feature presentation logic to our BookList component by editing its commented pagination section <!---→ so that it looks like shown below.
<Paginator class="" rows=10 @page="onPaginate" :totalRecords="totalBooks" /> By editing that pagination section, each time when our app is up and running the pagination feature will appear as appears below.
Conclusion
By reaching this far, I am pretty sure that you have gained a substantial amount of techniques and little skills to embark your journey as Vue Front end Developer. So far we have heavily made use of two kinds of vue resources:
local components as named previously
v-for directive
If you would like to pursue further in this arena there is a lot to learn about the Vue Framework’s tips, tricks and best practices regarding its resources’ varieties and their various types such as components, directives, forms, state management, design patterns, deployment and so forth.
I have used inline CSS styling within the component’s templates but that was simply done so because of the need for quick demonstration purposes. The best practices regarding applying styles to the component is to make use of the style section within the component
together with template and script sections. Check out https://vuejs.org website or similar online guide on how to do this. It is my hope that this tutorial will motivate you to take the next steps to become the rock-star Front end Developer with Vue. You may access this development project git repository
at https://github.com/barakaben/vue-elibrary/tree/master











