vue实现搜索过滤效果


Posted in Javascript onMay 28, 2019

本文实例为大家分享了vue实现搜索过滤效果的具体代码,供大家参考,具体内容如下

html:

<table id="tfhover_1" class="tftable_1" border="1">
  <tr>
    <th>名称</th>
    <th>链接状态</th>
    <th>IP</th>
    <th>特例类型</th>
    <th>所属城市</th>
    <th>所属机房</th>
  </tr>
  <tr v-cloak v-for="(item, index) of slist">
    <td>{{item.name}}</td>
    <td>{{item.username}}</td>
    <td>{{item.email}}</td>
    <td>{{item.sex}}</td>
    <td>{{item.province}}</td>
    <td>{{item.hobb}}</td>
    <!--<td><a href="javascript:;" rel="external nofollow" rel="external nofollow" @click="showOverlay(index)">修改</a> | <a href="javascript:;" rel="external nofollow" rel="external nofollow" @click="del(index)">删除</a></td>-->
  </tr>
</table>

css:

[v-cloak] {
  display: none
}
table {
  border: 1px solid #ccc;
  padding: 0;
  border-collapse: collapse;
  table-layout: fixed;
  /*margin-top: 10px;*/
  width: 100%;
  margin-top: 45px;
}
table td,
table th {
  height: 30px;
  border: 1px solid #ccc;
  background: #fff;
  font-size: 2vh;
  padding: 12px 3px 6px 8px;
  color: #666666;
  font-weight: 300;
}
table th:first-child {
  width: 4rem;
}
.container,
.st {
  /*width: 1000px;*/
  margin: 10px auto 0;
  font-size: 13px;
  font-family: '微软雅黑'
}
.container .search {
  font-size: 15px;
  padding: 4px;
}
.container .add {
  padding: 5px 15px;
}
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 6;
  background: rgba(0, 0, 0, 0.7);
}
.overlay td:first-child {
  width: 8rem;
}
.overlay .con {
  position: absolute;
  /*width: 420px;*/
  min-height: 300px;
  background: #fff;
  left: 50%;
  top: 50%;
  -webkit-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
  /*margin-top: -150px;*/
  padding: 20px;
}
 
.span_1{
  font-size: 18px;
  color: #666666;
}

js:

Vue.component('model', {
 
  template: '',
  props: ['list', 'isactive'],
  computed: {
    modifylist() {
      return this.list;
    }
  },
  methods: {
    changeActive() {
      this.$emit('change');
    },
    modify() {
      this.$emit('modify', this.modifylist);
    },
    add(){
 
    }
  }
});
 
 
var app = new Vue({
  el: '#app',
  data: {
    isActive: false,
    selected: -1,
    selectedlist: {},
    slist: [],
    searchlist: [],
    list: [
      {
        name:'Fe1',
        username: '开',
        email: '221.122.62.221',
        sex: '特例1',
        province: '北京',
        hobb:'电子机房'
      },
      {
        name:'Fe2',
        username: '关',
        email: '192.168.12.222',
        sex: '特例2',
        province: '上海',
        hobb: '服务机房'
      },
      {
        name:'Fe3',
        username: '开',
        email: '127.255.255.255',
        sex: '特例3',
        province: '重庆',
        hobb: '遥控机房'
      },
      {
        name:'Fe4',
        username: '关',
        email: '223.255.255.255',
        sex: '特例4',
        province: '北京市',
        hobb:'内网机房'
      }
    ]
  },
  created() {
    this.setSlist(this.list);
  },
  methods: {
    // 修改数据
    showOverlay(index) {
      this.selected = index;
      this.selectedlist = this.list[index];
      this.changeOverlay();
    },
    // 点击保存按钮
    modify(arr) {
      if (this.selected > -1) {
        Vue.set(this.list, this.selected, arr);
        this.selected = -1;
      } else {
        this.list.push(arr);
      }
      this.setSlist(this.list);
 
      this.changeOverlay();
    },
 
    del(index) {
      this.list.splice(index, 1);
      this.setSlist(this.list);
    },
    changeOverlay() {
      this.isActive = !this.isActive;
    },
    // 获取需要渲染到页面中的数据
    setSlist(arr) {
      this.slist = JSON.parse(JSON.stringify(arr));
    },
    // 搜索
    search() {
      var v = $('.search').val(),
        self = this;
      self.searchlist = [];
      if (v) {
        var ss = [];
        // 过滤需要的数据
        this.list.forEach(function (item) {
          if (item.province.indexOf(v) > -1) {
            if (self.searchlist.indexOf(item.province) == -1) {
              self.searchlist.push(item.province);
            }
            ss.push(item);
          } else if (item.hobb.indexOf(v) > -1) {
            if (self.searchlist.indexOf(item.hobb) == -1) {
              self.searchlist.push(item.hobb);
            }
            ss.push(item);
          }
        });
        this.setSlist(ss); // 将过滤后的数据给了slist
      } else {
        // 没有搜索内容,则展示全部数据
        this.setSlist(this.list);
      }
    }
  },
  watch: {
  }
})

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
ExtJS Window 最小化的一种方法
Nov 18 Javascript
使用SyntaxHighlighter实现HTML高亮显示代码的方法
Feb 04 Javascript
JS常用函数使用指南
Nov 23 Javascript
JavaScript获取一个范围内日期的方法
Apr 24 Javascript
js一维数组、多维数组和对象的混合使用方法
Apr 03 Javascript
全面解析Bootstrap中tab(选项卡)的使用方法
Jun 06 Javascript
JavaScript调试的多个必备小Tips
Jan 15 Javascript
JS实现商品筛选功能
Aug 19 Javascript
使用Webpack提升Vue.js应用程序的4种方法(翻译)
Oct 09 Javascript
js布局实现单选按钮控件
Jan 17 Javascript
vue 导航锚点_点击平滑滚动,导航栏对应变化详解
Aug 10 Javascript
Vue表单提交点击事件只允许点击一次的实例
Oct 23 Javascript
微信小程序 image组件遇到的问题
May 28 #Javascript
vue实现搜索功能
May 28 #Javascript
Bootstrap 时间日历插件bootstrap-datetimepicker配置与应用小结
May 28 #Javascript
如何实现双向绑定mvvm的原理实现
May 28 #Javascript
vue实现带复选框的树形菜单
May 27 #Javascript
vue实现按需加载组件及异步组件功能
May 27 #Javascript
Vue实现导航栏点击当前标签变色功能
Aug 19 #Javascript
You might like
Php做的端口嗅探器--可以指定网站和端口
2006/10/09 PHP
Linux下创建nginx脚本-start、stop、reload…
2014/08/03 PHP
PHP框架Laravel的小技巧两则
2015/02/10 PHP
Laravel 连接(Join)示例
2019/10/16 PHP
用脚本调用样式的几种方法
2006/12/09 Javascript
js 文件引入实现代码
2010/04/23 Javascript
jQuery Tools tooltip使用说明
2012/07/14 Javascript
document节点对象的获取方式示例介绍
2013/12/24 Javascript
js将控件隐藏及display属性的使用介绍
2013/12/30 Javascript
动态添加删除表格行的js实现代码
2014/02/28 Javascript
Javascript核心读书有感之类型、值和变量
2015/02/11 Javascript
JS上传图片前实现图片预览效果的方法
2015/03/02 Javascript
jQuery 判断图片是否加载完成方法汇总
2015/08/10 Javascript
jquery简单倒计时实现方法
2015/12/18 Javascript
jQuery前端开发35个小技巧
2016/05/24 Javascript
BootStrap Validator使用注意事项(必看篇)
2016/09/28 Javascript
RGB和YUV 多媒体编程基础详细介绍
2016/11/04 Javascript
解决Layui中layer报错的问题
2019/09/03 Javascript
Vue中点击active并第一个默认选中功能的实现
2020/02/24 Javascript
python实现监控linux性能及进程消耗性能的方法
2014/07/25 Python
Python 基础知识之字符串处理
2017/01/06 Python
Windows下安装Scrapy
2018/10/17 Python
python 发送和接收ActiveMQ消息的实例
2019/01/30 Python
Python 分享10个PyCharm技巧
2019/07/13 Python
以SQLite和PySqlite为例来学习Python DB API
2020/02/05 Python
Python爬虫教程之利用正则表达式匹配网页内容
2020/12/08 Python
美国专注于健康商品的网站:eVitamins
2017/01/23 全球购物
全球性的在线购物网站:Zapals
2017/03/22 全球购物
Kent & Curwen:与大卫·贝克汉姆合作
2017/06/13 全球购物
美国男士和女士奢侈品折扣手表购物网站:Certified Watch Store
2018/06/13 全球购物
FLOS美国官网:意大利高级照明工艺的传奇
2018/08/07 全球购物
Shopee菲律宾:在线购买和出售
2019/11/25 全球购物
保险经纪人求职信
2014/03/11 职场文书
电子商务助理求职自荐信
2014/04/10 职场文书
淘宝店策划方案
2014/06/07 职场文书
爱国主义主题班会
2015/08/14 职场文书