vue day8 table page

ゝ一纸荒年。 2022-01-06 02:04 207阅读 0赞
  1. @{
  2. ViewBag.Title = "Home Page";
  3. Layout = null;
  4. }
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>分页</title>
  10. <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
  11. <script type="text/javascript" src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
  12. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  13. </head>
  14. <body>
  15. <div id="app-4" class="col-xs-12 main-table-wrapper">
  16. <table class="table table-striped table-hover table-bordered" id="main-table">
  17. <thead>
  18. <tr>
  19. <th><input type="checkbox" v-model="checkall" v-on:click='checkAll'></th>
  20. <th>商品名称</th>
  21. <th>商品单价</th>
  22. <th>数量</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr v-for="(item,index) in tableData">
  27. <td><input type="checkbox" v-model="checked" :value="item.id" /> </td>
  28. <td>{
  29. { item.name }}</td>
  30. <td>{
  31. { item.address }}</td>
  32. <td>{
  33. { item.date }}</td>
  34. @*<td><button @click="handleRemove(index)">移除</button></td>*@
  35. </tr>
  36. </tbody>
  37. </table>
  38. <div>{
  39. {
  40. checked}}</div>
  41. </div>
  42. <ul class="pagination" id="page-break" v-if="seen">
  43. <li v-if="cur>5">
  44. <a v-on:click="cur=1,pageClick()" style="cursor:pointer">««</a>
  45. </li>
  46. <li v-if="cur>1">
  47. <a v-on:click="cur--,pageClick()" style="cursor:pointer">«</a>
  48. </li>
  49. <li v-if="cur-5>0">
  50. <a style="cursor:not-allowed">...</a>
  51. </li>
  52. <li v-for="item in indexs" v-bind:class="{'active':cur==item}">
  53. <a v-on:click="btnClick(item), pageClick()" style="cursor:pointer">{
  54. {item}}</a>
  55. </li>
  56. <li v-if="all-cur-4>0">
  57. <a style="cursor:not-allowed">...</a>
  58. </li>
  59. <li v-if="cur!=all">
  60. <a v-on:click="cur++,pageClick()" style="cursor:pointer">»</a>
  61. </li>
  62. <li v-if="cur!=all && all>10 && all-cur-4>0">
  63. <a v-on:click="cur=all,pageClick()" style="cursor:pointer">»»</a>
  64. </li>
  65. <li><a>Page {
  66. {cur}} of {
  67. {all}}</a></li>
  68. </ul>
  69. <script>
  70. var app = new Vue({
  71. el: '#app-4',
  72. data: {
  73. tableData: [
  74. ],
  75. checkall:false,
  76. checked:[]
  77. },
  78. methods: {
  79. handleRemove: function(index){
  80. this.tableData.splice(index,1);
  81. },
  82. checkAll: function () {
  83. var _this = this
  84. if (this.checkall) {
  85. // 实现反选
  86. this.checked = []
  87. } else {
  88. // 实现全选
  89. this.checked = []
  90. this.tableData.forEach(function (item) {
  91. _this.checked.push(item.id)
  92. })
  93. }
  94. if (this.checked.length === this.tableData.length) {
  95. this.checkall = true
  96. // console.log(this.checkall)
  97. // console.log(this.checked)
  98. }
  99. }
  100. }
  101. });
  102. var app1=new Vue({
  103. el: '#page-break',
  104. data: {
  105.             seen: true,
  106. cur: 1,
  107. all: 2
  108. },
  109. watch: {
  110. cur: function(newValue, oldValue){
  111. console.log(arguments);
  112. }
  113. },
  114. methods: {
  115. btnClick(num){
  116. if(num!=this.cur){
  117. this.cur=num;
  118. }
  119. },
  120. pageClick(){
  121. console.log('现在是'+this.cur+'页')
  122. loaddata(this.cur);
  123. },
  124. },
  125. computed: {
  126. indexs(){
  127. var left = 1;
  128. var right = this.all;
  129. var arr = [];
  130. if(this.all>=10){
  131. if(this.cur>5 && this.cur<this.all-4){
  132. left = this.cur-4;
  133. right = this.cur+4;
  134. }else if(this.cur<=6){
  135. left=1;
  136. right=10;
  137. }else{
  138. left=this.all-9;
  139. right=this.all;
  140. }
  141. }
  142. while(left<=right){
  143. arr.push(left);
  144. left++;
  145. }
  146. return arr;
  147. }
  148. }
  149. })
  150. function loaddata(page)
  151. {
  152. $.ajax({
  153. url: "@Url.Action("Data")",
  154. type: "Post",
  155. data: { pageIndex: page },
  156. dataType: "json",
  157. success: function (data) {
  158. app.tableData = data.rows;
  159. app1.all = data.total % 10 == 0 ? (data.total / 10) : (Math.floor(data.total / 10) + 1);
  160. },
  161. error: function (jqXHR, textStatus, errorThrown) {
  162. }
  163. });
  164. }
  165. loaddata(1);
  166. </script>
  167. </body>
  168. </html>
  169. public JsonResult Data(int pageIndex = 1, int pageSize = 10)
  170. {
  171. var product = new[]
  172. {
  173. new {id=1,date= "2016-05-02", name= "王小虎",address="上海市普陀区金沙江路 1518 弄"},
  174. new {id=2,date= "2016-04-02", name= "王小虎2",address="上海市普陀区金沙江路 1518 弄"},
  175. new {id=3,date= "2016-06-02", name= "王小虎3",address="上海市普陀区金沙江路 1518 弄"},
  176. new {id=4,date= "2016-07-02", name= "王小虎4",address="上海市普陀区金沙江路 1518 弄"},
  177. new {id=5,date= "2016-08-02", name= "王小虎5",address="上海市普陀区金沙江路 1518 弄"},
  178. new {id=6,date= "2016-09-02", name= "王小虎6",address="上海市普陀区金沙江路 1518 弄"},
  179. new {id=7,date= "2016-10-02", name= "王小虎7",address="上海市普陀区金沙江路 1518 弄"},
  180. new {id=8,date= "2016-11-02", name= "王小虎8",address="上海市普陀区金沙江路 1518 弄"},
  181. new {id=9,date= "2016-11-02", name= "王小虎8",address="上海市普陀区金沙江路 1518 弄"},
  182. new {id=11,date= "2016-11-02", name= "王小虎89",address="上海市普陀区金沙江路 1518 弄"},
  183. new {id=12,date= "2016-11-02", name= "王小虎89",address="上海市普陀区金沙江路 1518 弄"},
  184. new {id=13,date= "2016-11-02", name= "王小虎89",address="上海市普陀区金沙江路 1518 弄"},
  185. new {id=14,date= "2016-11-02", name= "王小虎89",address="上海市普陀区金沙江路 1518 弄"},
  186. new {id=15,date= "2016-11-02", name= "王小虎89",address="上海市普陀区金沙江路 1518 弄"},
  187. new {id=16,date= "2016-11-02", name= "王小虎89",address="上海市普陀区金沙江路 1518 弄"},
  188. new {id=17,date= "2016-11-02", name= "王小虎89",address="上海市普陀区金沙江路 1518 弄"},
  189. new {id=18,date= "2016-11-02", name= "王小虎81",address="上海市普陀区金沙江路 1518 弄"},
  190. new {id=19,date= "2016-11-02", name= "王小虎81",address="上海市普陀区金沙江路 1518 弄"},
  191. };
  192. return Json(new { total = product.Count(), rows = product.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList() }, JsonRequestBehavior.AllowGet);
  193. }

转载于:https://www.cnblogs.com/LiuFengH/p/10669381.html

发表评论

表情:
评论列表 (有 0 条评论,207人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Day 8

    今日阴雨绵绵 空气舒适,天雷滚滚 适合发呆 偶尔学习。 再次感受到屁股经验决定脑袋。 从某种角度上说 命运是固定的 决定的。你的立场 你的经验 一出生不就定型了么。所以没有

    相关 初体验egg-vue-singal-page

    egg在koa框架的基础上进行了封装,并集合了现今热门的vue、react框架,支持服务端渲染,可以说是全端开发的一个优秀实践。关于demo和api,可以在[官网][Link