<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="js/vue.js"></script>
</head>
<body>
<div class="" id="root">
<input type="text" v-model="wordKey" />
<ul>
<li v-for="(p,index) in fullpersons" :key="p.id">
{{p.name}}-{{p.age}}-{{p.sex}}
</li>
</ul>
</div>
<script>
new Vue({
el: '#root',
data: {
wordKey: '',
personlist: [{
id: 1,
name: '小明',
age: 15,
sex: '男'
},
{
id: 2,
name: '小樱',
age: 16,
sex: '女'
},
{
id: 3,
name: '樱花',
age: 17,
sex: '女'
},
{
id: 4,
name: '花朵',
age: 18,
sex: '女'
},
],
},
computed: {
fullpersons() {
return this.personlist.filter(x => x.name.indexOf(this.wordKey) !== -1)
}
}
})
</script>
</body>
</html>