Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. <div id="app" method="Post">
  2.  
  3.  
  4. <!-- Text input-->
  5.  
  6. <label class="col-md-4 control-label">Name</label>
  7. <div class="col-md-4">
  8. <input id="name" name="name" type="text" v-model="name" class="form-control input-md">
  9. </div>
  10.  
  11.  
  12. <!-- Text input-->
  13.  
  14. <label class="col-md-4 control-label" >Age</label>
  15. <div class="col-md-4">
  16. <input id="age" name="age" type="text" v-model="age" class="form-control input-md">
  17. </div>
  18.  
  19.  
  20. <!-- Text input-->
  21.  
  22. <label class="col-md-4 control-label">Email</label>
  23. <div class="col-md-4">
  24. <input id="email" name="email" type="text" v-model="email" class="form-control input-md">
  25. </div>
  26.  
  27.  
  28. <!-- Button -->
  29.  
  30. <label class="col-md-4 control-label" for="signup"></label>
  31. <div class="col-md-4">
  32. <button id="signup" v-on:click="Add()" class="btn btn-primary">Sign up!</button>
  33. <button id="edit" v-on:click="Reedit()" class="btn btn-primary">EDIT</button>
  34. </div>
  35.  
  36.  
  37.  
  38.  
  39. <table class="table">
  40. <tr>
  41. <th>#</th>
  42. <th>Name</th>
  43. <th>Age</th>
  44. <th>Email</th>
  45. </tr>
  46.  
  47. <tr v-for="participant in participants">
  48. <td> {{ participant.id }} </td>
  49. <td> {{ participant.name }} </td>
  50. <td> {{ participant.age }} </td>
  51. <td> {{ participant.email }} </td>
  52. <td><a v-on:click="Edit(participant)" class="btn bnt-default">Edit</a></td>
  53. <td><a v-on:click="Delete(participant)" class="btn bnt-default">Delete</a></td>
  54. </tr>
  55.  
  56. </table>
  57. </div>
  58. @section Scripts {
  59. <script>
  60. var app = new Vue({
  61. el:'#app',
  62.  
  63. data: {
  64. participants: [],
  65. id:null,
  66. name:'',
  67. age:null,
  68. email:''
  69. },
  70. created: function () {
  71. var self = this;
  72.  
  73. // Fetch list of authors
  74. axios.get('/api/Participants')
  75. .then(function (response) {
  76. self.participants=response.data;
  77. })
  78. },
  79.  
  80. methods: {
  81. Add: function(){
  82. axios.post('/api/Participants',{
  83. "name":this.name,
  84. "age":this.age,
  85. "email":this.email
  86. }).then(response=>{
  87. self.participants.push({
  88. "id":response.id,
  89. "name":self.name,
  90. "age":self.age,
  91. "email":self.email
  92. });
  93. self.name='';
  94. self.age=null;
  95. self.email='';
  96. });
  97.  
  98. },
  99. Reedit: function(participant){
  100. axios.put('/api/Participants/' + this.id,{
  101. "id":this.id,
  102. "name":this.name,
  103. "age":this.age,
  104. "email":this.email
  105. }).then(result=>{
  106. self.participants[this.id].name=self.name;
  107. self.participants[this.id].age=self.age;
  108. self.participants[this.id].email=self.email;
  109. self.name='';
  110. self.age=null;
  111. self.email='';
  112. });
  113. },
  114. Edit: function(participant){
  115. this.id=participant.id;
  116. this.name=participant.name;
  117. this.age=participant.age;
  118. this.email=participant.email;
  119. },
  120. Delete: function(participant){
  121. axios.delete('/api/Participants/' + participant.id);
  122. this.participants.splice(this.participants.indexOf(participant),1)
  123. }
  124. }
  125. })
  126. </script>
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement