列表渲染+计算属性实现搜索框功能
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="box">
<!-- v-model获取输入框值,双向绑定-->
<input type="text" v-model="mytext"/>
<ul>
<li v-for="data in computedDataList">
{{data}}
</li>
</ul>
</div>
<script type="text/javascript">
var vm = new Vue({
el:"#box",
data:{
dataList:['a','aa','abb','bbb','ccc','ddd'],
mytext:''
},
computed:{
computedDataList:function() {
return this.dataList.filter(item=>item.indexOf(this.mytext)>-1)
}
}
})
</script>
</body>
</html>