1. 程式人生 > >Vue.js結合bootstrap實現的分頁控制元件

Vue.js結合bootstrap實現的分頁控制元件

原文地址:http://blog.csdn.net/qiuhaotc/article/details/53031884

使用 vue.js 結合 bootstrap 開發的分頁控制元件

效果如下




實現程式碼

[html] view plain copy  print?
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <metacharset="utf-8"/>
  5.     <metaname="viewport"content="width=device-width, initial-scale=1.0"
    />
  6.     <title> Vue-PagerTest</title>
  7.     <linkrel="stylesheet"href="../lib/bootstrap/dist/css/bootstrap.css"/>
  8. </head>
  9. <body>
  10.     <divclass="container body-content">
  11.         <divid="test"class="form-group">
  12.             <divclass="form-group">
  13.                 <
    divclass="page-header">
  14.                     資料  
  15.                 </div>
  16.                 <tableclass="table table-bordered table-responsive table-striped">
  17.                     <tr>
  18.                         <th>姓名</th>
  19.                         <th>年齡</th>
  20.                         <
    th>刪除資訊</th>
  21.                     </tr>
  22.                     <trv-for="item in arrayData">
  23.                         <tdclass="text-center">{{item.name}}</td>
  24.                         <td>{{item.age}}</td>
  25.                         <td><ahref="javascript:void(0)"v-on:click="deleteItem($index,item.age)">del</a></td>
  26.                     </tr>
  27.                 </table>
  28.                 <divclass="page-header">分頁</div>
  29.                 <divclass="pager"id="pager">
  30.                     <spanclass="form-inline">
  31.                         <selectclass="form-control"v-model="pagesize"v-on:change="showPage(pageCurrent,$event,true)" number>
  32.                             <optionvalue="10">10</option>
  33.                             <optionvalue="20">20</option>
  34.                             <optionvalue="30">30</option>
  35.                             <optionvalue="40">40</option>
  36.                         </select>
  37.                     </span>
  38.                     <templatev-for="item in pageCount+1">
  39.                         <spanv-if="item==1"class="btn btn-default"v-on:click="showPage(1,$event)">
  40.                             首頁  
  41.                         </span>
  42.                         <spanv-if="item==1"class="btn btn-default"v-on:click="showPage(pageCurrent-1,$event)">
  43.                             上一頁  
  44.                         </span>
  45.                         <spanv-if="item==1"class="btn btn-default"v-on:click="showPage(item,$event)">
  46.                             {{item}}  
  47.                         </span>
  48.                         <spanv-if="item==1&&item<showPagesStart-1"class="btn btn-default disabled">
  49.                             ...  
  50.                         </span>
  51.