在vue中获取当前点击元素的方法:1.新建html项目,引入vue;2.插入div标签,绑定click事件;3.插入脚本标记,写入事件函数;
具体步骤如下:
1.首先,新建一个html项目,并在项目中引入vue;
<!DOCTYPE html><html>
<head>
<script src="./js/vue.js"></script>
<title></title>
</head>
<body>
</body>
</html>
2.vue引入好后,在项目中插入一个div标签,并将click事件与v-on标记进行绑定;
<!DOCTYPE html><html>
<head>
<script src="./js/vue.js"></script>
<title></title>
</head>
<body>
<div id="btnClick">
<button v-on:click = "searchBtn()">A</button>
<button v-on:click = "searchBtn()">B</button>
<button v-on:click = "searchBtn()">C</button>
</div>
</body>
</html>
3.最后,click事件绑定好后,在项目中插入脚本标记并写入事件函数即可获取当前点击的元素;
<!DOCTYPE html><html>
<head>
<script src="./js/vue.js"></script>
<title></title>
</head>
<body>
<div id="btnClick">
<button v-on:click = "searchBtn()">A</button>
<button v-on:click = "searchBtn()">B</button>
<button v-on:click = "searchBtn()">C</button>
</div>
<script>
let v =new Vue({
el:"#btnClick",
methods:{
searchBtn:function(btn){
alert(btn);
console,dir(btn):
}
}
});
</script>
</body>
</html>