xml
复制代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue Methods Option</title>
<script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
<h1>Vue Methods Option</h1>
<hr>
<div id="app">
{{message}}
<p><button @click="add(5,$event)">add</button></p>
<!--native调用原始事件-->
<p><whl @click.native="add(5,$event)"></whl></p>
</div>
<button οnclick="app.add(9)">外部ADD</button>
</body>
</html>
<script>
//声明一个组件
var whl={
template:`<button>组件ADD</button>`
}
var app = new Vue({
el:'#app',
data:{
message:1
},
components:{
'whl':whl
},
methods:{
//event 参数 可以打印出来看看
add:function(num,event){
// console.log(event);
if(num!=null){
this.message+=num
}else{
this.message++
}
}
}
})
</script>