vue实现简单的数据筛选
代码如下:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv...
·
代码如下:
<!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>
更多推荐
已为社区贡献1条内容
所有评论(0)