zoukankan      html  css  js  c++  java
  • vue_小项目_模糊搜索(列表过滤)_结果排序

    html

    •     <div id="test">
              <label>
                  <input type="text" v-model="searchWord" placeholder="搜索一下"/>
              </label>
              <button type="button" @click="orderType=1">原来排序</button>
              <button type="button" @click="orderType=2">升序排序</button>
              <button type="button" @click="orderType=3">降序排序</button>
              
              <ul>
                  <li v-for="(p, index) in searchResult">
                      {{p.name}}----{{p.age}}
                  </li>
              </ul>
              
          </div>

    js

    • <script src="./js/vue.js"></script>
          <script>
              new Vue({
                  el:"#test",
                  data(){
                      return {
                          persons:[
                              {name:"Tom", age:18},
                              {name:"Jack", age:16},
                              {name:"Jerry", age:15},
                              {name:"Kate", age:17},
                              {name:"Lee", age:14}
                          ],
                          searchWord: "",
                          orderType: 1
                      }
                  },
                  computed:{
                      searchResult(){
                          const {orderType, searchWord, persons} = this;
                          
                          let result = persons.filter(person=>person.name.indexOf(searchWord)!==-1);
                          
                          if(orderType !== 1){
                              result.sort((one, two)=>{
                                  if(orderType === 2){
                                      return one.age - two.age
                                  }else if(orderType === 3){
                                      return two.age - one.age
                                  }
                              })
                          }
                          
                          return result;
                      }
                  }
              })
          </script>

     

    --------小尾巴 ________一个人欣赏-最后一朵颜色的消逝-忠诚于我的是·一颗叫做野的心.决不受人奴役.怒火中生的那一刻·终将结束...
  • 相关阅读:
    nodepad++中的正则表达式匹配和替换操作。
    QT Creator配置环境和安装
    圣诞树小程序的制作
    C#编辑xml文件
    delegate里的Invoke和BeginInvoke
    记录RFID操作错误
    关于Panel隐藏横向滚动条
    随笔
    Java图形打印 上下对称三角星
    Centos 7.5安装 Redis 5.0.0
  • 原文地址:https://www.cnblogs.com/tianxiaxuange/p/10383855.html
Copyright © 2011-2022 走看看