本文实例为大家分享了Vue.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) //删除










