赞
踩
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> <script src="vue.js"></script> </head> <body> <div id="app"> <input type="text" v-model="txt" /> <ul> <li v-for="item in list">{{ item }}</li> </ul> </div> <script> var app = new Vue({ el: "#app", data: { txt: "", arr: [ "苹果", "哈密瓜", "西瓜", "芒果", "瓜子", "橘子", "火龙果", "西瓜", "南瓜" ] }, computed: { list() { var arr1 = []; var _this = this; this.arr.map(function(item) { if (item.indexOf(_this.txt) != -1) { arr1.push(item); } }); return arr1; } } }); </script> </body> </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。