0
点赞
收藏
分享

微信扫一扫

vue指令-v-on事件对象

花明 2023-07-28 阅读 34

vue指令-v-on事件对象

1、目的

vue事件处理函数中,拿到事件对象

2、语法

无传参数,通过形参直接接收

<template>
  <div id="app">
    <a @click="one" href="http://www.baidu.com">百度</a><br/>
  </div>
  
</template>

<script>


export default {
  //定义函数
  methods:{
    one(e){
      e.preventDefault()

    }
  }
  
}
</script>

传参,通过$event指代事件对象传给事件处理函数

<template>
  <div id="app">
    <a @click="two(10,$event)" href="http://www.baidu.com">百度</a><br/>
  </div>
  
</template>

<script>


export default {
  //定义函数
  methods:{
    two(num,e){
      e.preventDefault()

    }
  }
  
}
</script>
举报

相关推荐

0 条评论