<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue</title>
<script src="../vue.js"></script>
</head>
<body>
<div id="main">
<input type="text" v-model="searchData">
<ul>
<li v-for="data in getList">{{data}}</li>
</ul>
</div>
<script>
new Vue({
el: '#main',
data: {
dataList:['aaa','bbbb','cccc','dddd','abaa','cbcc','abc'],
searchData:''
},
methods: {
},
computed: {
getList() {
let reg = new RegExp(this.searchData);
return this.dataList.filter((value) => reg.test(value))
}
}
})
</script>
</body>
</html>
这个简洁多了