Advertisement
GDolganov

Table.Vue

Sep 16th, 2019
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.51 KB | None | 0 0
  1. <template>
  2.     <main>
  3.         <table>
  4.             <thead>
  5.                 <tr>
  6.                     <th @click="sort('name')">Name</th>
  7.                     <th @click="sort('birthday')">Birthday</th>
  8.                     <th @click="sort('email')">E-mail</th>
  9.                     <th @click="sort('phone')">Phone</th>
  10.                     <th @click="sort('distance')">Distance</th>
  11.                     <th @click="sort('finance')">Finance</th>
  12.                 </tr>
  13.             </thead>
  14.             <tbody>
  15.                 <tr>
  16.                     <td>{{user.name}}</td>
  17.                     <td>{{user.birthday}}</td>
  18.                     <td>{{user.email}}</td>
  19.                     <td>{{user.phone}}</td>
  20.                     <td>{{user.distance}}</td>
  21.                     <td>{{user.fiance}}</td>
  22.                 </tr>
  23.             </tbody>
  24.         </table>
  25.         <button @click="prevPage">Previous</button>
  26.         <button @click="nextPage">Next</button>
  27.     </main>
  28. </template>
  29. <script>
  30. import axios from 'axios';
  31. export default {
  32.   props: ['id'],
  33.   data() {
  34.     return {
  35.       post: null,
  36.       endpoint: 'src/users.json',
  37.     }
  38.   },
  39.   methods: {
  40.     getUser(id) {
  41.         axios(this.endpoint + id)
  42.         .then(response => {
  43.             this.post = response.data
  44.         })
  45.         .catch( error => {
  46.             console.log(error)
  47.         })
  48.     }
  49.   },
  50.   watch: {
  51.     '$route'() {
  52.       this.getUser(this.id);
  53.     }
  54.   },
  55.   created() {
  56.     this.getUser(this.id);
  57.     }
  58. }
  59. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement