没有$event事件 比如(react, 小程序等)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style lang="en">
#app11{
width: 100px;
height:100px;
background-color: aqua;
}
#app22{
width:100px;
height: 100px;
background-color: red;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
</head>
<body>
<div id="app">
<div @click="say" data-tname="吴彦祖" id="app11">吴彦祖</div>
<div @click="say" data-tname="郑州吴彦祖" id="app22">郑州吴彦祖</div>
</div>
<script>
new Vue({
el:"#app",
methods:{
// 自定义方法 不加小括号,下边e自动接收DOM标准的事件对象
say(e){
console.log(e)
// 原生方法获取传过来的值
var tname=e.target.dataset.tname;
console.log(`${tname}的点击位置x:${e.offsetX},y:${e.offsetY}`)
}
}
})
</script>
</body>
</html>