console
var app = new Vue({
el:'#app',
data:{
num:1
},
methods:{
add:function(){
return this.num++;
}
}
});
app.$on('reduce',function(){
console.log('执行了reduce方法')
this.num--;
});
app.$once('reduceOnce',function(){
console.log("只执行一次的方法");
this.num--;
})
var reduce = ()=>{
app.$emit("reduce");
}
var reduceOnce = ()=>{
app.$emit("reduceOnce");
}
function off(){
app.$off('reduce');
}
<script src="https://unpkg.com/vue"></script>
<script src="http://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<h1>实例事件</h1>
<hr />
<div id="app">
<p>{{num}}</p>
<button @click="add">add</button>
</div>
<button onclick="reduce()">reduce</button>
<button onclick="reduceOnce()">reduceOnce</button>
<button onclick="off()">off</button>
*:not(button){
color:#fff;
}
a:visited{
color:lightblue
}