This commit is contained in:
3056762376@qq.com 2022-11-03 16:53:15 +08:00
parent 7fcb9b872d
commit b3331413e7
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
<!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="../../../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>