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>
  • 相关阅读:
    理解 Javascript 执行上下文和执行栈
    CSS中选择器优先级的权重计算
    一年内经验前端面试题记录
    ie8兼容问题
    css文本两端对齐
    前端 SPA 单页应用数据统计解决方案 (ReactJS / VueJS)
    我在SharePoint行业的从业经历(一)
    android中的AlertDialog具体概述
    Android 最火的高速开发框架xUtils
    Project Euler:Problem 93 Arithmetic expressions
  • 原文地址:https://www.cnblogs.com/kukai/p/12857850.html
Copyright © 2011-2022 走看看