vue233/10-组件化开发/07-父子组件的通信/07-2子组件向父组件的通信(emit)/复习/复习子传父的练习.html

51 lines
1014 B
HTML

<!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>
</head>
<body>
<div id="app">
<apps @item="listitem"></apps>
</div>
<template id="apps">
<div>
<h1 v-for="item in list" @click="itemList(item)">{{item}}</h1>
</div>
</template>
</body>
<script src="../../../JavaScript/vue.js"></script>
<script>
new Vue({
el:"#app",
data:{
list:[]
},
methods:{
listitem(val){
this.list.push(val)
for (let i of this.list){
console.log(i);
}
}
},
components:{
'apps':{
template:"#apps",
data(){
return {
list:["电脑数码","电子设备","办公"]
}
},
methods: {
itemList(value){
this.$emit("item",value)
}
},
}
}
})
</script>
</html>