此为本人学习代码,参照千锋教育kerwin老师的视频所写,视频资源链接见文章末尾
代码运行效果
首先引入vue地址
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"> </script>
运用v-model 和key
<div id = "box">
<input type = "text" v-model="mytext"/>
<ul>
<li v-for ="data in test()" :key="data">
{
{data}}
</li>
</ul>
<!-- {
{ test() }} -->
</div>
导入可见数据
data:{
mytext:"",
datalist:["aaa","add","bbb","bbc","ccc","ddd","eee","ade"]
},
完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"> </script>
</head>
<body>
<div id = "box">
<input type = "text" v-model="mytext"/>
<ul>
<li v-for ="data in test()" :key="data">
{
{data}}
</li>
</ul>
<!-- {
{ test() }} -->
</div>
<script>
var vm = new Vue({
el:"#box",
data:{
mytext:"",
datalist:["aaa","add","bbb","bbc","ccc","ddd","eee","ade"]
},
methods:{
test(){
return this.datalist.filter(item=>item.includes(this.mytext))
}
}
})
</script>
</body>
</html>
此为学习模仿代码,参照千锋kerwin老师视频所写,链接为: 【千锋web前端开发项目教程_1000集完全零基础入门HTML5+CSS3+JS到精通(资料含前端学习路线图)-哔哩哔哩】 https://b23.tv/dJqyfv1