<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="vue.js"></script>
</head>
<body>
<div id="box">
<veb></veb>
<len></len>
</div>
</body>
<script>
Vue.component("veb",{
data:function(){
return{
num:1
}
},
template:"<h1>{{num}}</h1>",
created:function(){
car.$on("add",function(){
this.num++
}.bind(this))
}
})
Vue.component("len",{
template:"<button @click='add'>点击</button>",
methods:{
add:function(){
car.$emit("add")
}
}
})
//首先要有一个空的vue实例,同是根实例也要有
var car=new Vue();
var box=new Vue({
el:"#box",
})
</script>
</html>
网友评论