1.通过方法传参
2.通过属性传参
<template>
<view>
<button data-index="11" type="primary" @click="clickBtn(1, $event)">点击事件1</button>
<button data-index="22" type="primary" @click="clickBtn(2, $event)">点击事件2</button>
</view>
</template>
<script>
export default {
methods: {
clickBtn(index, event) {
console.log(index)
console.log(event)
// 获取data-index的值
console.log(event.currentTarget.dataset.index)
}
}
}
</script>
<style>
</style>
本文介绍了一种在Vue.js中通过点击按钮触发事件并传递参数的方法。具体展示了如何使用@click事件监听器,并通过方法和属性两种方式传递参数,同时演示了如何在事件处理函数中获取这些参数。
7480

被折叠的 条评论
为什么被折叠?



