温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Vue.js如何实现分页查询功能

发布时间:2021-04-21 10:41:32 来源:亿速云 阅读:266 作者:小新 栏目:web开发

这篇文章给大家分享的是有关Vue.js如何实现分页查询功能的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

js的作用是什么

1、能够嵌入动态文本于HTML页面。2、对浏览器事件做出响应。3、读写HTML元素。4、在数据被提交到服务器之前验证数据。5、检测访客的浏览器信息。6、控制cookies,包括创建和修改等。7、基于Node.js技术进行服务器端编程。

具体内容如下

vue.js的使用如下:

1、引入vue.js

<script src="~/js/vue2.2.4.js"></script>

   a、分页条

<ul class="pagination" id="pagination1"></ul>

    b、分页条js、css

<link href="~/css/page.css" rel="stylesheet" />
<script src="~/js/jqPaginator.js"></script>

2、分页的方法

 public JsonResult GrtUserData(int page,int rows)
 {
 //top分页法 row_number分页
 TextEntities tes = new TextEntities();
 //分页查询
 List<Users> ulist = tes.Users.OrderBy(a=>a.Id).Skip((page-1)*rows).Take(rows).ToList();
 int allcount = tes.Users.Count(); //总页数
 int allpage = allcount / rows;
 if (allcount % rows !=0)
 
 allpage = allpage + 1;
 DTO_Page dp = new DTO_Page();
 dp.data = ulist;
 dp.allpage = allpage;
 return Json(dp, JsonRequestBehavior.AllowGet);
 }

3、封装page方法

public class DTO_Page
 {
 public int rows { get; set; }
 public int allpage { get; set; }
 public List<Users> data { get; set; }
 }

4、定义获取总页数的方法

 public JsonResult GetAllpage(int rows)
 {
 TextEntities tes = new TextEntities();
 int allcount = tes.Users.Count(); //总页数
 int allpage = allcount / rows;
 if (allcount % rows != 0)
 allpage = allpage + 1;
 return Json(allpage);
 
 }

5、前台分页方法,获取后台的数据,实现分页的动态性

<script>
 //封装一个查询后台的方法
 var getdata = function (page, rows,vm) {
 $.ajax({
 url: '/home/GrtUserData',
 type: 'get',
 data: { page: page, rows: rows },
 success: function (dto_page) {
 vm.mydata = dto_page.data;
 $.jqPaginator('#pagination1', {
  totalPages: dto_page.allpage,
  visiblePages: 5,
  currentPage: page,
  onPageChange: function (num, type) {
  //怎么把第一次忽略
  if (type != "init") {
  //更新查询后的页面
  getdata(num, 5,vm);
  }
  }
 });
 }
 });
 }

 $(function () {
 //给更新div添加数据
 var update_vm = new Vue({
 el: "#updatecontent",
 data: {
 userinfo: {}
 }
 })
 
 //实例化 vue.js (用来给表格提供数据的) 只实例化一次
 var vm = new Vue({
 el: '#content',
 data: {
 mydata: []
 },
 methods: {
 butdelete: function (_id) //删除
 {
  $.post('/home/BatchDelete', { ids: _id }, function (result) {
  if (result > 0) {
  location.href = "/home/UserMan";
  }
  else {
  alert("删除失败");
  }
  });
 },
 butupdate: function (item, event) //更新
 {
  //使用jquery打开编辑状态
  //$(event.target).parent().parent().find("td:gt(0):lt(4)").each(function (index,item) {
  // $(item).html("<input type='text' style='width:50px' value=" + $(item).html() + ">");
  //});

  //复制对象
  // var databack = $.extend({},item);
  update_vm.$data.userinfo = item;
  layer.open({
  type: 1,
  area: ["300px", "230px"],
  title: "更新",
  content: $("#updatecontent"),
  btn: ["保存"],
  yes: function (index) {
  $.post('/home/Update', update_vm.$data.userinfo, function (result) {
  //可以把vue.js数据替换把更新后到页面
  // vm.$data.mydata.splice(1, 1, update_vm.$data.userinfo);
  });
  },
  cancel: function () //点击关闭按钮
  {
  // alert(databack.UserName);
  // console.log(databack);
  }
  });
 }
 }
 }); 

 //默认第一个请求
 getdata(2,5,vm);
 $("#deletebut").click(function () {
 //存放需要批量删除的id
 var ids = "";
 $(".mytable input[type='checkbox']:checked").each(function (index, item) {
 ids += $(item).val() + ",";
 });
 $.post('/home/BatchDelete', { ids: ids }, function (result) {
 if (result > 0) {
  location.href = "/home/UserMan";
 }
 else {
  alert("删除失败");
 }
 });
 });
 });
</script>

感谢各位的阅读!关于“Vue.js如何实现分页查询功能”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI