<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<style>
.active{color:#f00}
.texttanger{background:#ccc}
</style>
<body>
<div id="example-2">
<button @click="btn">按钮</button>
<div>{{msg}}</div>
</div>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script>
var vm = new Vue({
el: '#example-2',
data:{
msg:""
},
methods:{
btn(){
this.$emit('test','发送消息')
}
},
mounted: function () {
this.$nextTick(function () {
// Code that will run only after the
// entire view has been rendered
this.$on('test',function(msg){
console.log(msg)
this.msg=msg
})
})
}
})
/*
vm.$on('test',function(msg){
console.log(msg)
vm.msg=msg
})
*/
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<style>
.active{color:#f00}
.texttanger{background:#ccc}
</style>
<body>
<div id="example-2">
<button @click="btn">按钮</button>
<div>{{msg}}</div>
</div>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script>
var vm = new Vue({
el: '#example-2',
data:{
msg:""
},
methods:{
btn(){
this.$emit('test','发送消息')
}
},
mounted: function () {
this.$nextTick(function () {
// Code that will run only after the
// entire view has been rendered
this.$on('test',function(msg){
console.log(msg)
this.msg=msg
})
})
}
})
/*
vm.$on('test',function(msg){
console.log(msg)
vm.msg=msg
})
*/
</script>
</body>
</html>