<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>vue-列表分页</title>
<script src="js/vue.js"></script>
<script src="js/jquery.js"></script>
<style>
body {
font-family: "Segoe UI";
} li {
list-style: none;
} a {
text-decoration: none;
} .pagination {
position: relative;
} .pagination li {
display: inline-block;
margin: 0 5px;
} .pagination li a {
padding: .5rem 1rem;
display: inline-block;
border: 1px solid #ddd;
background: #fff;
color: #0E90D2;
} .pagination li a:hover {
background: #eee;
} .pagination li.active a {
background: #0E90D2;
color: #fff;
} table,
td {
border: 1px solid #cccccc;
border-collapse: collapse;
} table {
width: 1090px;
margin: 20px auto;
} tr {
line-height: 30px;
} td {
text-align: center;
}
</style>
</head> <body> <script type="text/x-template" id="page">
<ul class="pagination">
<li v-show="current != 1" @click="current-- && goto(current--)">
<a href="#">上一页</a>
</li>
<li v-for="index in pages" @click="goto(index)" :class="{'active':current == index}" :key="index">
<a href="#">{{index}}</a>
</li>
<li v-show="allpage != current && allpage != 0 " @click="current++ && goto(current++)">
<a href="#">下一页</a>
</li>
</ul>
</script>
<div id="app">
<table border="1">
<tr>
<th>ID</th>
<th>书名</th>
<th>作者</th>
<th>价格</th>
</tr>
<tr v-for="books in book">
<td>{{books.id}}</td>
<td>{{books.name}}</td>
<td>{{books.author}}</td>
<td>{{books.price}}</td>
</tr>
</table>
<page></page>
</div>
<script>
Vue.component("page", {
template: "#page",
data: function() {
return {
current: 1,
showItem: 5,
allpage: 2
}
},
computed: {
pages: function() {
var pag = [];
if(this.current < this.showItem) { //如果当前的激活的项 小于要显示的条数
//总页数和要显示的条数那个大就显示多少条
var i = Math.min(this.showItem, this.allpage);
while(i) {
pag.unshift(i--);
}
} else { //当前页数大于显示页数了
var middle = this.current - Math.floor(this.showItem / 2), //从哪里开始
i = this.showItem;
if(middle > (this.allpage - this.showItem)) {
middle = (this.allpage - this.showItem) + 1
}
while(i--) {
pag.push(middle++);
}
}
return pag
}
},
methods: {
goto: function(index) {
if(index == this.current) return;
this.current = index;
//这里可以发送ajax请求
console.log(index);
$.ajax({
type: "get",
url: '' + index + '.json',
dataType: "json",
success: function(data) {
vm.book = data.books;
console.log(vm.book)
}
}); }
},
mounted: function() {
var index = 1;
$.ajax({
type: "get",
url: '' + index + '.json',
dataType: "json",
success: function(data) {
vm.book = data.books;
console.log(vm.book)
}
});
}
}) var vm = new Vue({
el: '#app',
data: {
book: ''
}
})
</script>
</body> </html>

vue.js-列表分页的更多相关文章

  1. html+vue.js 实现分页可兼容IE

    当功能比较简单,在单一html中使用vue.js分页展示数据,并未安装脚手架,或使用相关UI框架,此时需要手写一个分页器,不失为最合理最便捷的解决方案, 先看一下实现效果: 上代码: 1.简单搞一搞 ...

  2. Vue.js实现分页

    效果图 代码 <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/1999/ ...

  3. js列表分页

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. 用vue实现列表分页和按钮操作

    为中华之崛起而读书 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  5. vue.js 列表追加项写法

    <ul id="app"> <template v-for="site in sites"> <li>{{ site.nam ...

  6. Vue.js的列表数据的同步更新方法

    这次给大家带来Vue.js的列表数据的同步更新方法,Vue.js列表数据同步更新方法的注意事项有哪些,下面就是实战案例,一起来看一下. 数组的 push(),pop(),shift(),unshift ...

  7. Vue.js报错Failed to resolve filter问题原因

    Vue.js报错Failed to resolve filter问题原因 金刚 vue Vue.js js javascript 之前使用vue.js写分页功能时,写了一个过滤器,发现一个比较奇怪的错 ...

  8. Vue.js 开发实践:实现精巧的无限加载与分页功能

    本篇文章是一篇Vue.js的教程,目标在于用一种常见的业务场景--分页/无限加载,帮助读者更好的理解Vue.js中的一些设计思想.与许多Todo List类的入门教程相比,更全面的展示使用Vue.js ...

  9. 基于Vue.js的表格分页组件

    有一段时间没更新文章了,主要是因为自己一直在忙着学习新的东西而忘记分享了,实在惭愧. 这不,大半夜发文更一篇文章,分享一个自己编写的一个Vue的小组件,名叫BootPage. 不了解Vue.js的童鞋 ...

  10. 关于vue.js中列表渲染练习

    html: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8 ...

随机推荐

  1. CRM - 销售与客户

    一.销售与客户 - 表结构 ---公共客户(公共资源) 1.没有报名 2.3天没有跟进 3.15天没有成单 客户分布表 龙泰 男 yuan 2018-5-1 3天未跟进 龙泰 男 三江 2018-5- ...

  2. public boolean onKeyDown(int keyCode, KeyEvent event)

    @Override 2 public boolean onKeyDown(int keyCode, KeyEvent event) { 3 // TODO Auto-generated method ...

  3. grep命令做永久别名 显示颜色

    grep命令做永久别名  显示颜色 http://jingyan.baidu.com/article/22fe7ced17c1543002617f9c.htmlhttp://blog.csdn.net ...

  4. 驼峰命名和下划线命名互转php实现

    驼峰命名和下划线命名经常需要互转,下面提供两种php的实现方式.第一种方法效率相对差一些,实现方式如下: //驼峰命名转下划线命名 function toUnderScore($str) { $dst ...

  5. hive两大表关联优化试验

    呼叫结果(call_result)与销售历史(sale_history)的join优化: CALL_RESULT: 32亿条/444G SALE_HISTORY:17亿条/439G 原逻辑 Map: ...

  6. CentOS 7 集群使用NTP进行时间同步

    NTP时钟同步方式说明NTP在linux下有两种时钟同步方式,分别为直接同步和平滑同步: 直接同步 使用ntpdate命令进行同步,直接进行时间变更.如果服务器上存在一个12点运行的任务,当前服务器时 ...

  7. AtCoder Grand Contest 030 Solution

    A - Poisonous Cookies 签到. #include <bits/stdc++.h> using namespace std; #define ll long long l ...

  8. 11月26号host

    127.0.0.1 localhost255.255.255.255 broadcasthost::1 localhostfe80::1%lo0 localhost # Google start216 ...

  9. AVAudioFoundation(4):音视频录制

    本文转自:AVAudioFoundation(4):音视频录制 | www.samirchen.com 本文主要内容来自 AVFoundation Programming Guide. 采集设备的音视 ...

  10. Win10下安装Go开发环境

    关于Go语言有多么值得学习,这里就不做介绍了,既然看了这篇文章,想必是对有学习意向. 这里是在Windows下安装Go环境,去中文社区的下载栏目,https://studygolang.com/dl ...