example_of_vue_element.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Vue入门</title>
  6. <style>
  7. /*
  8. #emp {
  9. border-collapse: collapse;
  10. }
  11. #emp td, #emp th {
  12. border-bottom: 1px solid black;
  13. width: 120px;
  14. text-align: center;
  15. }
  16. */
  17. #page {
  18. width: 100%;
  19. text-align: center;
  20. margin-top: 20px;
  21. }
  22. /*
  23. #page a {
  24. text-decoration: none;
  25. color: #67C23A;
  26. cursor: pointer;
  27. margin: 20px 20px;
  28. }
  29. */
  30. h1 {
  31. color:#909399;
  32. }
  33. </style>
  34. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  35. </head>
  36. <body>
  37. <div id="app">
  38. <h1>员工信息表</h1>
  39. <hr>
  40. <el-table v-loading="loading" :data="emps" stripe style="width: 100%">
  41. <el-table-column prop="no" label="编号" width="180"></el-table-column>
  42. <el-table-column prop="name" label="姓名" width="180"></el-table-column>
  43. <el-table-column prop="job" label="职位"></el-table-column>
  44. <el-table-column prop="sal" label="工资"></el-table-column>
  45. <el-table-column prop="comm" label="补贴"></el-table-column>
  46. <el-table-column prop="dept.name" label="所在部门"></el-table-column>
  47. </el-table>
  48. <!--
  49. <table id="emp">
  50. <thead>
  51. <tr>
  52. <th>编号</th>
  53. <th>姓名</th>
  54. <th>职位</th>
  55. <th>工资</th>
  56. <th>补贴</th>
  57. <th>所在部门</th>
  58. </tr>
  59. </thead>
  60. <tbody>
  61. <tr v-for="emp in emps">
  62. <td>{{ emp.no }}</td>
  63. <td>{{ emp.name }}</td>
  64. <td>{{ emp.job }}</td>
  65. <td>{{ emp.sal }}</td>
  66. <td>{{ emp.comm }}</td>
  67. <td>{{ emp.dept.name }}</td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. -->
  72. <div id="page">
  73. <el-button type="primary" round @click="prevPage()">上一页</el-button>
  74. <el-button type="primary" round @click="nextPage()">下一页</el-button>
  75. </div>
  76. </div>
  77. <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
  78. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  79. <script>
  80. let pageSize = 5
  81. const app = new Vue({
  82. el: '#app',
  83. data: {
  84. emps: [],
  85. currentPage: 1,
  86. totalPage: 0,
  87. loading: true
  88. },
  89. created() {
  90. this.getEmpData()
  91. },
  92. methods: {
  93. getEmpData() {
  94. this.loading = true
  95. const url = `http://120.77.222.217/api/emps/?page=${this.currentPage}`
  96. fetch(url, {
  97. headers: {
  98. "token": "35ad60445cea11e99e1000163e02b646",
  99. }
  100. })
  101. .then(resp => resp.json())
  102. .then(json => {
  103. setTimeout(() => {
  104. this.emps = json.results
  105. this.totalPage = parseInt((json.count - 1) / pageSize) + 1
  106. this.loading = false
  107. }, 1000)
  108. })
  109. },
  110. prevPage() {
  111. if (this.currentPage > 1) {
  112. this.currentPage -= 1
  113. this.getEmpData()
  114. }
  115. },
  116. nextPage() {
  117. if (this.currentPage < this.totalPage) {
  118. this.currentPage += 1
  119. this.getEmpData()
  120. }
  121. }
  122. }
  123. })
  124. </script>
  125. </body>
  126. </html>