Vue2删除了Vue1里很实用的过滤器,我非常心痛啊,现在来学习一下用官方推荐的用计算属性实现的搜索过滤功能吧!
<body> <div class="app"> <input type="text" v-model="name"> <ul> <li v-for="user in newUsers" > {{ user.name }} </li> </ul> </div> <script> new Vue({ el: '.app', data: { name: '', users: [ { name: 'Bruce' }, { name: 'Chuck' }, { name: 'Jackie' }, { name: '赵' } ] }, computed: { newUsers: function () { var that = this; return that.users.filter(function (user) { return user.name.toLowerCase().indexOf(that.name.toLowerCase()) !== -1; }) } } }) </script> </body>