vue实现鼠标移入表格某一行鼠标箭头变为禁用符号
时间: 2023-09-04 11:09:30 浏览: 195
可以在表格的行数据上绑定 `mouseenter` 和 `mouseleave` 事件,当鼠标移入时将对应行的鼠标样式设置为禁用符号,移出时恢复原样式,具体实现可以参考以下代码:
```html
<template>
<table>
<thead>
<tr>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in tableData" :key="index" @mouseenter="handleMouseEnter(index)" @mouseleave="handleMouseLeave(index)" :style="{'cursor': cursorStyle[index]}">
<td>{{ item.name }}</td>
<td>{{ item.age }}</td>
<td>{{ item.gender }}</td>
</tr>
</tbody>
</table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: '张三', age: 18, gender: '男' },
{ name: '李四', age: 20, gender: '女' },
{ name: '王五', age: 22, gender: '男' }
],
cursorStyle: []
}
},
methods: {
handleMouseEnter(index) {
this.$set(this.cursorStyle, index, 'not-allowed')
},
handleMouseLeave(index) {
this.$set(this.cursorStyle, index, 'default')
}
}
}
</script>
```
在上述代码中,我们在表格的行数据上绑定了 `mouseenter` 和 `mouseleave` 事件,并在 `handleMouseEnter` 和 `handleMouseLeave` 事件处理函数中设置了对应行的鼠标样式,使用 `$set` 方法来动态设置 `cursorStyle` 数组中对应项的值,从而实现了鼠标移入表格某一行鼠标箭头变为禁用符号的效果。
阅读全文
相关推荐













