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之小功能统计
摘要:项目中经常会要用到大大小小的功能,所以我在这里进行一个汇总,后面会持续添加至这篇博客,希望当你遇到这个功能时,我的博客能够对你有帮助,(上一篇博客说要在收假后写一篇博客做一个年终总结,想了半天不 ...
随机推荐
- GCC编译器原理(一)------GCC 工具:addr2line、ar、as、c++filt和elfedit
1.3 GCC 工具 1.3.1 binutils 工具集 工具 描述 addr2line 给出一个可执行文件的内部地址,addr2line 使用文件中的调试信息将地址翻译成源代码文件名和行号. ar ...
- 【PgSQL安装(含配置)】PostgreSQL简称PgSQL,是1980以加利福尼亚大学开发的DBMS,严格遵守标准SQL。
[下载地址]http://www.enterprisedb.com/products-services-training/pgdownload#windows …………………………………………………… ...
- Django之CRM项目Day4-编辑客户 公私户 模糊查询
1.增加客户 2.编辑客户 obj = models.Customer.objects.filter(pk=edit_id).first() form_obj = CustomerForm(insta ...
- antd card 组件实现鼠标移入移出效果
鼠标移出: 鼠标移入: import React, { Component } from 'react' import { Card, Icon, Avatar } from 'antd'; cons ...
- 阿里云CentOS7.2卸载CDH5.12
#####################删除前最好将之前的下载的rpm包和parcels包备份一下##################### 1.停止serviceservice cloudera- ...
- 配置mongo
Windows 平台安装 MongoDB MongoDB 下载 MongoDB 提供了可用于 32 位和 64 位系统的预编译二进制包,你可以从MongoDB官网下载安装,MongoDB 预编译二进制 ...
- Java基础_0309:this关键字
this简介 在Java中this可以完成三件事情:表示本类属性.表示本类方法.当前对象(只是先介绍概念) 调用本类属性 在一个类中定义的方法中可以直接访问类中的属性,但是很多时候有可能会出现方法参数 ...
- 【报错】java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession
报错 java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession 或者 java.lang.ClassNotFound ...
- Log4j日志根据配置输出到多个自定义文件
最近工作中遇到所有日志需要记录到一个文件,而错误的sql执行记录到另一个文件中,查询了一些资料搞定,记录下来.顺便吐槽下公司限制印象笔记的使用. ##log4j.rootLogger=INFO, CO ...
- Akka Quickstart with Java-笔记
官方文档: http://developer.lightbend.com/guides/akka-quickstart-java/?_ga=2.177525157.1012573474.1504767 ...