事件使用·

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../vue/vue.js">

</script>
<div id="root">
<button v-on:click="showInfo">点击弹出alert1</button>
<button @click="showInfo1(44,event)">点击弹出alert2</button>
</div>
</head>
<body>
<!-- 事件基本使用:
1.使用v-on:click 或 @click绑定事件,其中click是事件名称
2.事件的回调需要配置在methods对象中,最终会在vm上
3.methods中配置的函数,不要用箭头函数!否则this就不是vm,而是window
4.methods中配置的函数,都是被vue所管理的函数,this的指向是vm 或 组织实例对象
5.@click="demo" 和 @click = "demo($event)"效果一致,但后者可以传参 -->
<script type="text/javascript">
new Vue({
el : "#root",
methods: {
showInfo() {
alert('111')
},
showInfo1(number) {
alert(number)
console.log(event)
}
}
})
</script>
</body>
</html>

posted on 2022-10-31 09:41  爱前端的小魏  阅读(16)  评论(0编辑  收藏  举报

导航