In this article, we will learn about basic concepts of Vue.js and how to install Vue.js and create a new project. We will also learn how to perform HTTP Get operation to fetch data in a Vue.js application.
What is Vue.js
Vue.js is an open-source front-end JavaScript framework for building user interfaces and single-page applications (SPAs). Vue.js is commonly referred to as Vue. and pronounced as View.
As per official Vue.js documentation,
Vue is a progressive framework for building user interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable. The core library is focused on the view layer only, and is easy to pick up and integrate with other libraries or existing projects. On the other hand, Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with modern tooling and supporting libraries.
Vue was created by Evan You, who was then working for Google using AngularJs in their projects
Prerequisites
- Basic knowledge of HTML and JavaScript.
- Text editor (We use Visual studio code)
Vue.js Installation
In this article, we will use Vue CLI to install and create vue project.
We use the following command to install Vue.js using CLI.
- npm install -g @vue/cli
Create Vue.js Project
Create a Vue.js project by using the following command.
- vue create demo1
Now Install the Axios library using the following command. Learn more about Axios.
- npm install --save axios
Install bootstrap using the following command.
- npm install bootstrap-vue bootstrap --save
- import 'bootstrap/dist/css/bootstrap.css'
- import 'bootstrap-vue/dist/bootstrap-vue.css'
Now right click on the Src folder and add a new file named 'Http-comman.js'.and add following code in this file.
- import axios from "axios";
- export default axios.create({
- baseURL: "https://localhost:44314/",
- headers: {
- "Content-type": "application/json"
- }
- });
Now right click on the Src folder and add a new file named 'Employeeservice.js'.and add following code in this file.
- import http from "./Http-comman";
- class EemployeeService {
- getAll() {
- return http.get("/api/EmployeeInfo/Getemployeeinfo");
- }
- }
- export default new EemployeeService();
Now right click on the Src folder > components folder and create a new componnet named 'Employeedata.vue'.and add following code in this file.
- <template>
- <div class="row" style="margin-bottom: 10px;">
- <div class="col-sm-12 btn btn-success">
- How to fetch data from WEB API in Vue.js Application
- </div>
- </div>
- <div>
- <table class="table">
- <thead>
- <th>Id</th>
- <th>Name</th>
- <th>City</th>
- <th>Age</th>
- <th>Technology</th>
- <th></th>
- </thead>
- <tbody>
- <tr v-for="item in employees" :key="item.Id">
- <td>{{item.Id}}</td>
- <td>{{item.Name }}</td>
- <td>{{item.City }}</td>
- <td>{{item.Age}}</td>
- <td>{{item.Tech}}</td>
- </tr>
- </tbody>
- </table>
- </div>
- </template>
- <script>
- import EemployeeService from "../Employeeservice";
- export default {
- name: 'Employeelist',
- data() {
- return {
- employees: [],
- };
- },
- created()
- {
- this.retrieveemployees();
- },
- methods: {
- retrieveemployees() {
- EemployeeService.getAll().then(response => {
- this.employees = response.data;
- console.log(response.data);
- })
- .catch(e => {
- console.log(e);
- });
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- </style>











Join the conversation! Your thoughts help the community grow.