vue222/10-组件化开发/09-组件插槽使用/复习/复习子组件传递父组件.html

53 lines
1.1 KiB
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 @num="show"></apps>
<div v-for="li in list">{{li}}</div>
</div>
<template id="tpl">
<div>
<h1>这是子组件内的列表</h1>
<ul v-for="list in item">
<li>{{list}}</li>
</ul>
<button @click="linkNumber()">点击我传值</button>
</div>
</template>
</body>
<script src="../../../00-tools/JavaScript/vue.js"></script>
<script>
new Vue({
el:"#app",
data:{
list:[]
},
methods: {
show(val){
this.list.push(val)
}
},
components:{
'apps':{
template:"#tpl",
data(){
return {
item:['这是内容1', '这是内容2', '这是内容3','这是内容4']
}
},
methods: {
linkNumber(){
this.$emit('num',this.item)
}
},
}
}
})
</script>
</html>