Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. <template>
  2. <div id="pageTable">
  3. <v-container grid-list-xl fluid>
  4. <v-layout row wrap>
  5. <v-flex sm12>
  6. <h3>Training</h3>
  7. </v-flex>
  8. <v-flex lg12>
  9. <v-dialog
  10. v-model="dialog"
  11. width="500"
  12. >
  13. <v-btn
  14. slot="activator"
  15. color="blue-grey"
  16. dark
  17. >
  18. Add User
  19. </v-btn>
  20.  
  21. <v-card>
  22. <v-card-title
  23. class="headline grey lighten-2"
  24. primary-title
  25. >
  26. Add User
  27. </v-card-title>
  28.  
  29. <v-card-text>
  30. <v-form >
  31. <v-text-field
  32. v-model="users.name"
  33. label="Name"
  34. required
  35. ></v-text-field>
  36. <v-text-field
  37. v-model="users.address"
  38. label="Adress"
  39. required
  40. ></v-text-field>
  41. </v-form>
  42. </v-card-text>
  43.  
  44. <v-divider></v-divider>
  45.  
  46. <v-card-actions>
  47. <v-spacer></v-spacer>
  48. <v-btn
  49. slot="activator"
  50. color="success"
  51. dark
  52. @click="dialog = false"
  53. v-on:click="AddNewUsers"
  54. >
  55. Add User
  56. </v-btn>
  57. </v-card-actions>
  58. </v-card>
  59. </v-dialog>
  60. <v-btn color="success" v-on:click="getAllDatas">Get All</v-btn>
  61. </v-flex>
  62. <v-flex lg12>
  63. <v-card>
  64. <v-toolbar card color="white">
  65. </v-toolbar>
  66. <v-divider></v-divider>
  67. <v-card-text class="pa-0">
  68. <p>Headers</p>
  69. <v-card >
  70. <p></p>
  71. </v-card>
  72. <template>
  73. <v-data-table
  74. :headers="complex.headers"
  75. :items="user"
  76. class="elevation-1"
  77. >
  78. <template slot="items" slot-scope="props">
  79. <td class="text-xs-left">{{ props.item.name }}</td>
  80. <td class="text-xs-left">{{ props.item.address}}</td>
  81. <td>
  82. <v-dialog
  83. v-model="dialogs"
  84. width="500"
  85. >
  86. <v-btn
  87. slot="activator"
  88. color="red lighten-2"
  89. dark
  90. v-on:click="getById(props.item._id)"
  91. >
  92. ID
  93. </v-btn>
  94. <v-card>
  95. <v-card-text>
  96. <ul v-for="user in uuser" >
  97. <p>name = {{user.name}}</p>
  98. <p >adress = {{user.address}}</p>
  99. </ul>
  100.  
  101. </v-card-text>
  102.  
  103. <v-divider></v-divider>
  104.  
  105. <v-card-actions>
  106. <v-spacer></v-spacer>
  107. <v-btn
  108. color="primary"
  109. flat
  110. @click="dialog = false"
  111. >
  112. I accept
  113. </v-btn>
  114. </v-card-actions>
  115. </v-card>
  116. </v-dialog>
  117. </td>
  118. <td>
  119. <v-btn color="error" v-on:click="deleteItems(props.item._id)" @click="snackbar = true">delete
  120. </v-btn>
  121. </td>
  122. </template>
  123. </v-data-table>
  124. <v-snackbar
  125. v-model="snackbar"
  126. :top="y === 'top'"
  127. :vertical="mode === 'vertical'"
  128. >
  129. {{ text }}
  130. <v-btn
  131. color="pink"
  132. flat
  133. @click="snackbar = false"
  134. >
  135. Close
  136. </v-btn>
  137. </v-snackbar>
  138.  
  139. </template>
  140. </v-card-text>
  141. </v-card>
  142. </v-flex>
  143. </v-layout>
  144. </v-container>
  145. </div>
  146. </template>
  147.  
  148. <script>
  149. import axios from 'axios'
  150. export default {
  151. data () {
  152. return {
  153. user : [],
  154. uuser : '',
  155. dialog : false,
  156. dialogs : false,
  157.  
  158. // snackbar
  159. snackbar: false,
  160. y: 'top',
  161. x: null,
  162. mode: '',
  163. timeout: 6000,
  164. text: 'success',
  165. // insert,
  166. users : {
  167. name : '',
  168. address : ''
  169. },
  170. //data Tables
  171. complex: {
  172. headers: [
  173. {
  174. text: 'Name',
  175. value: 'name'
  176. },
  177. {
  178. text: 'Address',
  179. value: 'address'
  180. },
  181.  
  182. ],
  183. },
  184. }
  185. },
  186. methods: {
  187. getAllDatas : function(){
  188. let items = this;
  189. let url = 'http://localhost:5000/user';
  190.  
  191. axios.get(url).then(function(res){
  192. items.user = res.data
  193. console.log(res.data)
  194. })
  195. .catch( function(err){
  196. console.log(err)
  197. } )
  198. },
  199. getById : function(id) {
  200. let self = this
  201. let url = 'http://localhost:5000/user/' + id
  202. axios.get(url).then((res) => {
  203. self.uuser = res.data
  204. console.log(res.data)
  205. })
  206. },
  207. deleteItems: function(id) {
  208. let url = 'http://localhost:5000/user/' + id
  209. axios.delete(url).then((res) => {
  210. console.log(res.data)
  211. })
  212. },
  213. AddNewUsers: function() {
  214. let url = 'http://localhost:5000/user'
  215. axios.post(url, {
  216. name : this.users.name,
  217. address : this.users.address
  218. })
  219. .then((res) => {
  220. console.log(res.data)
  221. })
  222. },
  223. }
  224. };
  225. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement