关于分页,这个里我们直接重置一下v-for的indexs,就是循环的结束值。因为v-for没有很好的办法设置步长以及怎么设置初始值
看代码
[JavaScript] 纯文本查看 复制代码 computed: {
indexs: function () {
//开始页
var left = 1;
//结束页
var right = this.pageCount;
//在显示的页码数组
var ar = [];
if (this.pageCount >= 10) {
if (this.pageIndex > 6 && this.pageIndex < this.pageCount - 4) {
left = this.pageIndex - 5
right = this.pageIndex + 4
} else {
if (this.pageIndex <= 6) {
left = 1
right = 10
} else {
right = this.pageCount
left = this.pageCount - 8
}
}
}
while (left <= right) {
ar.push(left)
left++
}
return ar
}
}
直接复制到你的vue对象中,然后配置一下
pageCount总页数
pageIndex当前页就行了。
控制数据是否显示,这里直接用一个隐藏的行来处理
html部分
[HTML] 纯文本查看 复制代码 <tr id="msg" style="display:none;" ></tr>
默认不显示
js控制如下,加载中,,,
[JavaScript] 纯文本查看 复制代码 $("#msg").html(" <td align='center' colspan='4'>数据加载中...</td>");
$("#msg").show();
没有数据时
[JavaScript] 纯文本查看 复制代码 rw.userlogs ="";
$("#msg").html("<td align='center' colspan='4'>未查询到数据...</td>");
出错时
[JavaScript] 纯文本查看 复制代码 $("#msg").html("<td align='center' colspan='4'>出现异常,请联系管理员!!!</td>");
全部JS部分
[JavaScript] 纯文本查看 复制代码 <script type="text/javascript">
var rw = new Vue({
el: "#grid",
data: {
pageIndex: 1, //当前页
pageCount: 0, //总页数
totalcount: 0, //总行数
username: "", //
userlogs: ""//用户列表集合
},
methods: {
getdata: function (n) {
rw.pageCount = 0;
rw.totalcount = 0;
rw.pageIndex = 0;
rw.userlogs = "";
$("#msg").html(" <td align='center' colspan='4'>数据加载中...</td>");
$("#msg").show();
axios({
method: 'get',
url: "/System/Crm_User_logs.aspx?action=getpagelist&username=" + this.username + "&pageIndex=" + n
}).then(function (res) {
var data = res.data;
if (data.reCode > 0) {
$("#msg").hide();
rw.pageCount = Math.ceil(data.TotalCount / data.pageSize);
rw.totalcount = data.TotalCount;
rw.username = data.username;
rw.pageIndex = data.pageIndex;
rw.userlogs = data.info;
} else {
$("#msg").html("<td align='center' colspan='4'>未查询到数据...</td>");
}
}).catch(function(err){
$("#msg").html("<td align='center' colspan='4'>出现异常,请联系管理员!!!</td>");
});
}
},
computed: {
indexs: function () {
//开始页
var left = 1;
//结束页
var right = this.pageCount;
//在显示的页码数组
var ar = [];
if (this.pageCount >= 10) {
if (this.pageIndex > 6 && this.pageIndex < this.pageCount - 4) {
left = this.pageIndex - 5
right = this.pageIndex + 4
} else {
if (this.pageIndex <= 6) {
left = 1
right = 10
} else {
right = this.pageCount
left = this.pageCount - 8
}
}
}
while (left <= right) {
ar.push(left)
left++
}
return ar
}
}
});
</script>
全部代码
[HTML] 纯文本查看 复制代码 <style>
.form-control
{
float: right;
}
.si-form
{
padding-top: 10px;
margin: 0 3px 3px 3px;
}
.tractive
{
background-color: rgb(240, 248, 255);
}
.acursor
{
cursor:pointer;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" runat="server">
<div class="si-main">
<div class="si-block">
<div class="si-form" id="grid">
<table class="table table-form">
<tr>
<td colspan="3">
<div class="form-control-wrap">
<label class="form-label">
用户名:</label>
<input class="form-control ml1" v-model="username" @keyup.enter="getdata(1)"/>
</div>
<button class="btn btn-primary" v-on:click="getdata(1)">
搜索</button>
</td>
</tr>
</table>
<%--分页列表--%>
<table class="table table-page">
<thead>
<tr>
<td align="center">
用户名
</td>
<td align="center">
登录时间
</td>
<td align="center">
登录IP
</td>
<td align="center">
useragent
</td>
</tr>
</thead>
<tbody>
<tr v-for="(info,index) in userlogs" :class="{'tractive':index%2!=0}">
<td align="center">
{{ info.User_name}}
</td>
<td align="center">
{{ info.StrUser_createdate}}
</td>
<td align="center">
{{ info.User_ip}}
</td>
<td align="center">
{{ info.User_useragent}}
</td>
</tr>
<tr id="msg" style="display:none;" ></tr>
</tbody>
<tfoot>
<tr>
<td colspan="11">
<div class="pagination-wrap">
<div class="count">
<div>
总页数 {{ pageCount}} 总记录数 {{ totalcount}}
</div>
</div>
<ul class="pagination" v-if="pageCount > 1">
<li v-if="pageIndex>1"><a class="acursor" href="javascripit:void(0)" v-on:click="getdata(1)">
首页</a></li>
<li v-if="pageIndex>1"><a class="acursor" v-on:click="pageIndex--,getdata(pageIndex)">
上一页</a></li>
<li v-for="n in indexs" v-bind:class="pageIndex === n ? 'cur':''"><a class="acursor"
v-on:click="getdata(n)">{{ n }}</a> </li>
<li v-if="pageIndex!=pageCount"><a class="acursor" v-on:click="pageIndex++,getdata(pageIndex)">
下一页</a></li>
<li v-if="pageIndex!=pageCount"><a class="acursor" v-on:click="getdata(pageCount)">
尾页</a></li>
</ul>
</div>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="js" runat="server">
<script type="text/javascript">
var rw = new Vue({
el: "#grid",
data: {
pageIndex: 1, //当前页
pageCount: 0, //总页数
totalcount: 0, //总行数
username: "", //
userlogs: ""//用户列表集合
},
methods: {
getdata: function (n) {
rw.pageCount = 0;
rw.totalcount = 0;
rw.pageIndex = 0;
rw.userlogs = "";
$("#msg").html(" <td align='center' colspan='4'>数据加载中...</td>");
$("#msg").show();
axios({
method: 'get',
url: "/System/Crm_User_logs.aspx?action=getpagelist&username=" + this.username + "&pageIndex=" + n
}).then(function (res) {
var data = res.data;
if (data.reCode > 0) {
$("#msg").hide();
rw.pageCount = Math.ceil(data.TotalCount / data.pageSize);
rw.totalcount = data.TotalCount;
rw.username = data.username;
rw.pageIndex = data.pageIndex;
rw.userlogs = data.info;
} else {
$("#msg").html("<td align='center' colspan='4'>未查询到数据...</td>");
}
}).catch(function(err){
$("#msg").html("<td align='center' colspan='4'>出现异常,请联系管理员!!!</td>");
});
}
},
computed: {
indexs: function () {
//开始页
var left = 1;
//结束页
var right = this.pageCount;
//在显示的页码数组
var ar = [];
if (this.pageCount >= 10) {
if (this.pageIndex > 6 && this.pageIndex < this.pageCount - 4) {
left = this.pageIndex - 5
right = this.pageIndex + 4
} else {
if (this.pageIndex <= 6) {
left = 1
right = 10
} else {
right = this.pageCount
left = this.pageCount - 8
}
}
}
while (left <= right) {
ar.push(left)
left++
}
return ar
}
}
});
</script>
|