<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/vue.min.js"></script>
</head>
<body>
<div id="itany">
<ul class="form-ul">
<li class="form-item">
<h4 class="form-title">邮件主题</h4>
<ele-input v-on:name="handleList"></ele-input>
<!-- <my-input :value="item" @input="val => {item = val}"></my-input>-->
<i class="icon pen"></i>
</li>
</ul>
<ul class="form-ul">
<li class="form-item" v-for="(v,k) in Arr" :key="k">
{{v}}
</li>
</ul>
</div>
<script>
Vue.component(
'eleInput',{
template: '<input type="text" @input="pushArr" v-model="name" >\
',
data: function(){
return{
name:""
}
},
methods:{
pushArr: function () {
this.$emit('name',{item:this.name});
}
}
}
)
var vm=new Vue({
el:"#itany",
data:function(){
return{
Arr:[],
Arrpost:['大华','小华', 'alex', 'mark']
};
},
methods:{
handleList: function (payload) {
var temp=[];
this.Arrpost.forEach(
function(val){
if(val.indexOf(payload.item)!=-1&&(payload.item!="")){
temp.push(val);
}
}
);
this.Arr=temp;
}
}
})
</script>
</body>
</html>
请把上面的代码中 <li class="form-item" v-for="(v,k) in Arr" :key="k">{{v}}</li>
拆成另外个组件,并实现和ele-input组件的通信,参考官方文档https://cn.vuejs.org/v2/guide/components.html#非父子组件通信
12345678_0001
相关分类