zoukankan      html  css  js  c++  java
  • vue里的过滤加排序操作示例

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
      </head>
      <body>
        <div id="app">
          <template v-for="user in userSort">
            <li>姓名:{{user.name}}</li>
          </template>
        </div>
        <script>
          var v = new Vue({
            el: "#app",
            data: {
              userInfo: [
                { name: "zhangsan" },
                { name: "aisi" },
                { name: "wangwu" },
              ],
            },
            computed: {
    //过滤方法
                userFilter:function(){
                    return this.userInfo.filter(function(user){
                        return user.name.match(/s/);
                    })
                },
    //排序方法
                userSort:function(){
    //a,b为任意参数,代表遍历的当前元素或对象(此处代表的是user)
                    return this.userFilter.sort(function(a,b){
                        return a.name.length-b.name.length;
                    })
                }
            },
          });
        </script>
      </body>
    </html>
  • 相关阅读:
    PHP数组操作,数组排序,数组元素操作,数组元素定位
    提高PHP编程效率的53个要点
    javascript的一些简单的应用
    数字时钟
    一个限定变量范围的小技巧
    windows编程学习——1 关闭窗口不退出
    比木马NB多了
    模拟时钟
    恶搞程序——黑屏
    用白色画笔再画一遍,代替擦除
  • 原文地址:https://www.cnblogs.com/kukai/p/12857850.html
Copyright © 2011-2022 走看看