Home » Simple Vue js CRUD Example Tutorial From Scratch

Simple Vue js CRUD Example Tutorial From Scratch

Today, We want to share with you Simple Vue js CRUD Example Tutorial From Scratch.In this post we will show you Basic CRUD Operations Using Vue.js Example, hear for VueJS CRUD Operations in Laravel we will give you demo and example for implement.In this post, we will learn about Creating a simple CRUD application with Laravel 5 and Vue.js with an example.

Simple Vue js CRUD Example Tutorial From Scratch

There are the Following The simple About Simple Vue js CRUD Example Tutorial From Scratch Full Information With Example and source code.

As I will cover this Post with live Working example to develop Vue.js CRUD application, so the some major files and Directory structures for this example is following below.

  • index.html

HTML interface View

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.

<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>Simple Vue js CRUD Example Tutorial From Scratch - pakainfo.com</title>
    <link rel='stylesheet prefetch' href='bootstrap.min.css'>
    <link rel='stylesheet prefetch' href='bootstrap-theme.min.css'>
</head>
<body>
<div class="container">
  <header class="page-header">
    <div class="branding">
      <img src="https://vuejs.org/images/logo.png" alt="Logo" title="Home page" class="logo"/>
      <h1>Simple Vue js CRUD Example Tutorial From Scratch - pakainfo.com</h1>
    </div>
  </header>
  <main id="app"></main>
</div>
<template id="billreceipt-list">
  <section>
  <div class="actions">
    <router-link class="btn btn-default" :to="{path: '/billreceipt-add'}">
      <span class="glyphicon glyphicon-plus"></span>
      Add billreceipt
    </router-link>
  </div>
  <div class="filters row">
    <div class="form-group col-sm-3">
      <label for="search-element">billreceipt name</label>
      <input v-model="searchKey" class="form-control" id="search-element" requred/>
    </div>
  </div>
  <table class="table">
    <thead>
    <tr>
      <th>Name</th>
      <th>Detail</th>
      <th>Rate</th>
      <th class="col-sm-2">Actions</th>
    </tr>
    </thead>
    <tbody>
    <tr v-for="billreceipt in filteredbillreceipts">
      <td>
        <router-link :to="{name: 'billreceipt', params: {billreceipt_id: billreceipt.id}}">{{ billreceipt.name }}</router-link>
      </td>
      <td>{{ billreceipt.detail }}</td>
      <td>
        {{ billreceipt.rate }}
        <span class="glyphicon glyphicon-euro" aria-hidden="true"></span>
      </td>
      <td>
        <router-link class="btn btn-warning btn-xs" :to="{name: 'billreceipt-edit', params: {billreceipt_id: billreceipt.id}}">Edit</router-link>
        <router-link class="btn btn-danger btn-xs" :to="{name: 'billreceipt-delete', params: {billreceipt_id: billreceipt.id}}">Delete</router-link>
      </td>
    </tr>
    </tbody>
  </table>
  </section>
</template>
<template id="billreceipt-add">
    <section>
  <h2>Add new billreceipt</h2>
  <form v-on:submit="createbillreceipt">
    <div class="form-group">
      <label for="add-name">Name</label>
      <input class="form-control" id="add-name" v-model="billreceipt.name" required/>
    </div>
    <div class="form-group">
      <label for="add-detail">Detail</label>
      <textarea class="form-control" id="add-detail" rows="10" v-model="billreceipt.detail"></textarea>
    </div>
    <div class="form-group">
      <label for="add-rate">Rate, <span class="glyphicon glyphicon-euro"></span></label>
      <input type="number" class="form-control" id="add-rate" v-model="billreceipt.rate"/>
    </div>
    <button type="submit" class="btn btn-success">Create</button>
     <router-link class="btn btn-default" :to="{path: '/'}">Cancel</router-link>
  </form>
</section>
</template>
<template id="billreceipt">
    <section>
  <h2>{{ billreceipt.name }}</h2>
  <b>Detail: </b>
  <div>{{ billreceipt.detail }}</div>
  <b>Rate:</b>
  <div>{{ billreceipt.rate }}<span class="glyphicon glyphicon-euro"></span></div>
  <br/>
  <span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>
  <router-link to="'/'">Back to billreceipt list</router-link>
</section>
</template>
<template id="billreceipt-edit">
    <section>
  <h2>Edit billreceipt</h2>
  <form v-on:submit="updatebillreceipt">
    <div class="form-group">
      <label for="edit-name">Name</label>
      <input class="form-control" id="edit-name" v-model="billreceipt.name" required/>
    </div>
    <div class="form-group">
      <label for="edit-detail">Detail</label>
      <textarea class="form-control" id="edit-detail" rows="3" v-model="billreceipt.detail"></textarea>
    </div>
    <div class="form-group">
      <label for="edit-rate">Rate, <span class="glyphicon glyphicon-euro"></span></label>
      <input type="number" class="form-control" id="edit-rate" v-model="billreceipt.rate"/>
    </div>
    <button type="submit" class="btn btn-success">Save</button>
    <router-link to="'/'" class="btn btn-default">Cancel</router-link>
  </form>
</section>
</template>
<template id="billreceipt-delete">
    <section>
  <h2>Delete billreceipt {{ billreceipt.name }}</h2>
  <form v-on:submit="deletebillreceipt">
    <p>The action cannot be undone.</p>
    <button type="submit" class="btn btn-danger">Delete</button>
    <router-link to="'/'" class="btn btn-default">Cancel</router-link>
  </form>
</section>
</template>
<script src='view/vue.min.js'></script>
<script src='view/vue-router.min.js'></script>
<script src="view/index.js"></script>
</body>
</html>

VueJs Source Code

index.js

var billreceipts = [
  {id: 1, name: 'Vuejs pakainfo.com', detail: 'Provide Vuejs Information.', rate: 1200},
  {id: 2, name: 'Angular 6 pakainfo.com', detail: 'Provide Angular 6 Information.', rate: 1200},
  {id: 3, name: 'Laravel 5.6 pakainfo.com', detail: 'Provide Laravel 5.6 Information.', rate: 1200}
];
function findbillreceipt (billreceiptId) {
  return billreceipts[findbillreceiptKey(billreceiptId)];
};
function findbillreceiptKey (billreceiptId) {
  for (var key = 0; key < billreceipts.length; key++) {
    if (billreceipts[key].id == billreceiptId) {
      return key;
    }
  }
};
var List = Vue.extend({
  template: '#billreceipt-list',
  data: function () {
    return {billreceipts: billreceipts, searchKey: ''};
  },
  computed : {
    filteredbillreceipts: function () {
    var self = this;
    console.log()
    return self.billreceipts.filter(function (billreceipt) {
      return billreceipt.name.indexOf(self.searchKey) !== -1
    })
  }
}
});
var billreceipt = Vue.extend({
  template: '#billreceipt',
  data: function () {
    return {billreceipt: findbillreceipt(this.$route.params.billreceipt_id)};
  }
});
var billreceiptEdit = Vue.extend({
  template: '#billreceipt-edit',
  data: function () {
    return {billreceipt: findbillreceipt(this.$route.params.billreceipt_id)};
  },
  methods: {
    updatebillreceipt: function () {
      var billreceipt = this.billreceipt;
      billreceipts[findbillreceiptKey(billreceipt.id)] = {
        id: billreceipt.id,
        name: billreceipt.name,
        detail: billreceipt.detail,
        rate: billreceipt.rate
      };
      router.push('/');
    }
  }
});
var billreceiptDelete = Vue.extend({
  template: '#billreceipt-delete',
  data: function () {
    return {billreceipt: findbillreceipt(this.$route.params.billreceipt_id)};
  },
  methods: {
    deletebillreceipt: function () {
      billreceipts.splice(findbillreceiptKey(this.$route.params.billreceipt_id), 1);
      router.push('/');
    }
  }
});
var Addbillreceipt = Vue.extend({
  template: '#billreceipt-add',
  data: function () {
    return {billreceipt: {name: '', detail: '', rate: ''}
    }
  },
  methods: {
    createbillreceipt: function() {
      var billreceipt = this.billreceipt;
      billreceipts.push({
        id: Math.random().toString().split('.')[1],
        name: billreceipt.name,
        detail: billreceipt.detail,
        rate: billreceipt.rate
      });
      router.push('/');
    }
  }
});
var router = new VueRouter({
  routes: [{path: '/', component: List},
    {path: '/billreceipt/:billreceipt_id', component: billreceipt, name: 'billreceipt'},
    {path: '/billreceipt-add', component: Addbillreceipt},
    {path: '/billreceipt/:billreceipt_id/edit', component: billreceiptEdit, name: 'billreceipt-edit'},
  {path:   '/billreceipt/:billreceipt_id/delete', component: billreceiptDelete, name: 'billreceipt-delete'}
]});
new Vue({
  el: '#app',
  router: router,
  template: ''
});

Simple Vue js CRUD Example Tutorial From Scratch – Output

Simple Vue js CRUD Example Tutorial From Scratch - output
Simple Vue js CRUD Example Tutorial From Scratch – output
Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Export Json Array to CSV using php Example

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Simple Vue js CRUD Example Tutorial From Scratch.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  vuejs crud Insert Update Delete operations Example and demo
  2. Read Also:  Create Different CSS Geometric Shapes with Example
  3. Read Also:  Preview Image before Upload using vuejs
  4. Read Also:  sql join multiple tables with conditions
  5. Read Also:  Yii Framework Introduction and Hello World Tutorial
  6. Read Also:  PHP Codeigniter URL Routing Automatically
  7. Read Also:  UI Grid Filtering using Angular Example
  8. Read Also:  Nested Child Routes in Vuejs Navigate Menu
  9. Read Also:  how to check empty array in laravel controller?
  10. Read Also:  Vue.js Simple CRUD Tutorial Example From Scratch

Leave a Comment

Your email address will not be published. Required fields are marked *