十、多个vue对象,相互调用
<script>
var v1=new Vue({
el:"#app",//div的id
data:{
name:"小明"
},
methods:{
//方法中有默认参数,event,通过event.target可以拿到绑定此事件的标签
methodTest(){
alert("方法测试");
}
}
});
var v2=new Vue({
el:"#app2",//div的id
data:{
age:11
},
methods:{
//方法中有默认参数,event,通过event.target可以拿到绑定此事件的标签
app2MethodTest(event){
v1.methodTest();
v1.name="大明";
}
}
});
</script>
网友评论