vue/10-组件化开发/07-父子组件的通信/07-1父组件向子组件的通信(props)/练习计数器.html

51 lines
945 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 :new_apps="count"></apps>
<button @click="add()">+</button>
<button @click="rev()">-</button>
</div>
<template id="tpl">
<div>
<h1>{{new_apps}}</h1>
</div>
</template>
</body>
<script src="../../../00-tools/JavaScript/vue.js"></script>
<script>
new Vue({
el:"#app",
data:{
count:0
},
methods: {
add(){
this.count+=1
},
rev(){
this.count-=1
}
},
components:{
'apps':{
template:"#tpl",
props:{
'new_apps': {
type: Number,
default() {
return 0
}
}
}
}
}
})
</script>
</html>