<!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. Nginx正向代理配置

    服务器端: server { resolver 8.8.8.8; resolver_timeout 5s; listen 0.0.0.0:8888; access_log /usr/local/ngi ...

  2. The Accomodation of Students---hdu2444(二分图,最大匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2444 题意:有n个学生,m个关系,但是如果a认识b,b认识c,但是a不一定认识c: 求能不能把这n个人 ...

  3. 商铺项目(Logback配置与使用)

    <?xml version="1.0" encoding="utf-8"?> <configuration debug="false ...

  4. PAT 1128 N Queens Puzzle[对角线判断]

    1128 N Queens Puzzle(20 分) The "eight queens puzzle" is the problem of placing eight chess ...

  5. 2.4 The Object Model -- Computed Properties and Aggregate Data with @each(计算的属性和使用@each聚合数据)

    1. 通常,你可能有一个计算的属性依赖于数组中的所有元素来确定它的值.例如,你可能想要计算controller中所有todo items的数量,以此来确定完成了多少任务. export default ...

  6. eclipse引入httpServlet源码

    eclipse引入httpServlet源码 展开Apache Tomcat v7.0[Apache Tomcat v7.0] -> servlet-api.jar 找到 -> http ...

  7. cocos代码研究(8)持续动作子类学习笔记

    理论部分 时间间隔动作(ActionInterval)是一个在一段时间内执行的动作. 它有一个开始时间和完成时间.完成时间等于起始时间加上持续时间. ActionInterval的子类与位置有关的动作 ...

  8. java之对象适配器

    对象的适配器模式 与类的适配器模式一样,对象的适配器模式把被适配的类的API转换成目标类的API,与类的适配器模式不同的是,对象的适配器模式不是使用继承关系连接到Adaptee类,而是使用委派关系连接 ...

  9. .Ignite是什么

    Ignite是什么 Apache Ignite内存数据组织是高性能的.集成化的以及分布式的内存平台,他可以实时地在大数据集中执行事务和计算,和传统的基于磁盘或者闪存的技术相比,性能有数量级的提升.  ...

  10. springcloud17---zuul-reg-exp

    package com.itmuch.cloud; import org.springframework.boot.SpringApplication; import org.springframew ...