vue---分页搜索功能
<template>
<div>
<div class="searc">
<input type="search" placeholder="请输入搜索关键字" v-model='msg' v-on:keyup='fileterImg'>
</div>
<table class="table">
<tr>
<th>ID</th>
<th>音乐标题</th>
<th>音乐时间</th>
<th>音乐类型</th>
<th>作者</th>
<th>上传人</th>
<th>审核状态</th>
<th>操作</th>
</tr>
<tr v-for='item in list' :id='item.id'>
<td>{{item.id}}</td>
<td>{{item.title}}</td>
<td>{{item.times}}</td>
<td>{{item.kinds}}</td>
<td>{{item.author}}</td>
<td>{{item.men}}</td>
<td>{{item.look}}</td>
<td>{{item.id}}</td>
</tr>
</table>
<div class="pages">
<nav aria-label="Page navigation">
<ul class="pagination">
<li>
<a href="javascript:;" aria-label="Previous" v-if='num>1' @click='num=1,pageClick()'>
<span aria-hidden="true">«</span>
</a>
</li>
<li v-for='(item,index) in page'><a href="javascript:;" @click='num=index+1,pageClick(index)'>{{item}}</a></li>
<li>
<a href="javascript:;" aria-label="Next" v-if='num!=page' @click='num++,pageClick()'>
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</template> <script>
export default {
name: 'hello',
data () {
return {
dataList:[],//总数据
page:'',//总页数
list:[],//循环数据
num:1,//默认第一页
pageNum:8,//每页显示多少
msg:''
}
},
mounted(){
var _this = this
this.$http.get('.././static/list.json').then(function(res){
_this.dataList = res.data.list
_this.list = _this.dataList.filter(function(data,index){
if(index>=(_this.num-1)*_this.pageNum&&index<_this.pageNum*_this.num){
return data;
}
})
_this.page =Math.ceil(_this.dataList.length/8);
})
},
methods:{
pageClick(index){
var _this = this;
if(index!=this.num){
this.list = this.dataList.filter(function(data,index){
if((parseInt(index/_this.pageNum)+1) == _this.num){
return data
}
})
}
},
fileterImg(){
var _this = this;
this.list = this.dataList.filter(function(data,index){
if(data.title.indexOf(_this.msg)!==-1){
return data;
}
})
_this.page = Math.ceil(_this.list.length/8)
}
}
}
</script>
<style scope>
td{
text-align: left;
border-bottom: 1px solid #ddd;
height: 45px;
}
</style>
改进版。分页+搜索功能
<template>
<div>
<div class="search-box">
<input type="text" placeholder="请输入搜索信息" v-model='query'>
</div>
<div class="table">
<table>
<tr>
<th>名称</th>
<th>单价</th>
<th>数量</th>
<th>缩略图</th>
</tr>
<tr v-for="item in showLists">
<td>{{item.name}}</td>
<td>{{item.format}}</td>
<td>{{item.number}}</td>
<td><img :src="item.img" alt="img"></td>
</tr>
</table>
<h4 v-if="showText">暂无这信息</h4>
</div>
<div class="pages">
<ul>
<li class="page-btn" @click="changePage(-1)">上一页</li>
<li>第<input type="text" v-model="showPage">页</li>
<li>总共{{totalPage}}页</li>
<li class="page-btn" @click="changePage(1)">下一页</li>
</ul>
</div>
</div>
</template>
<script>
require('es6-promise').polyfill();
require('isomorphic-fetch');
export default{
name:'table',
data(){
return{
arrList:[],
totalPage:0,
limitPage:8,
showPage:1,
showList:[],
filterList:[],
query:'',
showText:false
}
},
mounted(){
this.$nextTick(()=>{
this.getList();
})
},
computed:{
showLists(){
this.getShowList();
this.listFilter();
return this.showList;
}
},
methods:{
getList(){
fetch('./static/list.json').then((res)=>{
return res.json()
}).then((stroies)=>{
this.arrList = stroies.list;
/*this.showList = this.arrList.filter((item,index)=>{
if(index<this.limitPage*this.showPage && index>=this.limitPage*(this.showPage-1)){
return item;
}
})*/
this.getShowList();
})
},
getShowList(){
this.showList = this.arrList.slice((this.showPage-1)*this.limitPage,this.showPage*this.limitPage)
this.totalPage = Math.ceil(this.arrList.length/this.limitPage)
},
changePage(num){
if(num === 1){
this.showPage++;
if(this.showPage>this.totalPage){
this.showPage = this.totalPage;
console.log('last')
}
}else if(num === -1){
this.showPage--;
if(this.showPage<=1){
this.showPage = 1;
console.log('first')
}
}
this.getShowList()
},
listFilter(){
if(this.query){
this.filterList = this.arrList.filter((item)=>{
return item.name.indexOf(this.query)>-1
})
if(this.filterList.length===0){
this.showText = true;
}
this.showList = this.filterList.slice((this.showPage-1)*this.limitPage,this.showPage*this.limitPage)
this.totalPage = Math.ceil(this.filterList.length/this.limitPage)
}else{
this.showText = false;
}
}
},
watch:{
query(){
console.log(this.query)
}
}
}
</script>
vue---分页搜索功能的更多相关文章
- vue实现搜索功能
vue实现搜索功能 template 部分 <!-- 搜索页面 --> <template> <div> <div class="goback&qu ...
- Vue下简单分页及搜索功能
最近利用Vue和element ui仿写了个小页面,记一哈分页和搜索功能的简单实现. 首页 emmmm..... 搜索框输入..... 搜索完成 数据是直接写在这里面的: cardPhoto:[ ...
- CI 结合 vue.js 的搜索功能模块
CI 结合 vue.js 的搜索功能模块 最近在有优化公司后台的某个模块的搜索功能优化 原先的是这个样子的,很是单调: 老大给我找个图希望我能弄成这样子: 经过不断修改,最后成了这样子 是不是比以前好 ...
- ajax分页效果、分类联动、搜索功能
一.使用smarty+ajax+php实现无刷新分页效果 效果图 <!DOCTYPE html> <html lang="en"> <head> ...
- vue自动完成搜索功能的数据请求处理
在现在的互联网世界里,自动完成的搜索功能是一个很常见的功能.比如百度.搜狗.360搜索 ... 功能描述一下大概是这个样子的:有一个搜索框,用户在里面输入要查询的条件,系统会“智能”判断用户输完了,然 ...
- 原生javascript实现分页效果+搜索功能
一.概述 首先,我们要明确为何需要分页技术,主要原因有以下: 1.分页可以提高客户体验度,适当地选择合适的数据条数,让页面显得更有条理,使得用户体验感良好,避免过多数据的冗余. 2.提高性能的需要. ...
- vue 使用watch监听实现类似百度搜索功能
watch监听方法,watch可以监听多个变量,具体使用方法看代码: HTML: <!doctype html> <html lang="en"> < ...
- Vue 分页功能伪代码实现
Vue分页功能的实现 其实分页功能是一个比较简单的demo 后端写好pageNum和pageSize的接口直接传参就是了 // 这里我们假设后端已经写好了 pageNum和pagesize <v ...
- 我的Vue之小功能统计
摘要:项目中经常会要用到大大小小的功能,所以我在这里进行一个汇总,后面会持续添加至这篇博客,希望当你遇到这个功能时,我的博客能够对你有帮助,(上一篇博客说要在收假后写一篇博客做一个年终总结,想了半天不 ...
随机推荐
- Python中json一点小知识
import json dic={ "name":"杨林" } ret=json.dumps(dic,ensure_ascii=False) #因为json.d ...
- 【python小练】0001
第 0001 题:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)? # coding ...
- python DB-API
python为数据库访问开发了统一的API(Application Programming Interface,应用程序编程接口):DB-API. MySQL的实现叫做MySQLdb,Oracle实现 ...
- 修改输入框placeholder的样式
1. h5页面: //修改placeholder 样式 (chrome,其余类似加前缀) ::-webkit-input-placeholder { color:rgba(21,30,38,0.35) ...
- linux系统下python升级安装
1.安装gcc gcc-c++ yum install -y gcc gcc-c++ #提前检查是否安装 2.下载python3.5.2安装包 cd /usr/local/src/ wget http ...
- JDK开发环境搭建及环境变量配置
Java配置----JDK开发环境搭建及环境变量配置 1. 下载安装安装JDK开发环境 http://www.oracle.com/technetwork/java/javase/downloads/ ...
- 5-8套接字socket
socket概念 socket层 理解socket Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协 ...
- 通过Cookie统计上次网页访问时间
servlet类: import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date; import ...
- SQLQueryStress
工具介绍及使用链接:http://www.cnblogs.com/lyhabc/p/3187922.html 工具下载链接:http://files.cnblogs.com/files/coce/sq ...
- linux scanf函数%d后加空白
参考链接: https://bbs.csdn.net/topics/390389059 关键点: scanf()中空白字符(包括/n,space)会使scanf()函数在读操作中略去输入中的零个或者一 ...