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

51 lines
1.0 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 @btn_click="shower"></apps>
<h1>{{num}}</h1>
</div>
<template id="tpl">
<div>
<h1>这是子组件{{dnum}}</h1>
<button @click="Changes()">点击</button>
</div>
</template>
</body>
<script src="../../../00-tools/JavaScript/vue.js"></script>
<script>
new Vue({
el:"#app",
data:{
num:0
},
methods:{
shower(val){
this.num="这是父组件"+val
}
},
components:{
'apps':{
template:"#tpl",
data(){
return {
dnum:"HelloVueComponents"
}
},
methods: {
Changes(){
this.$emit("btn_click",this.dnum)
}
},
}
}
})
</script>
</html>