javascript - 在一行表上显示按钮
问题描述
我有表:
<table class="table table-condensed">
<thead>
<tr>
<th>id</th>
<th>task</th>
<th>date</th>
</tr>
</thead>
<tbody>
<tr v-for="row in tasks">
<td span @mouseover="showButtonFunction" @mouseleave="hideButtonFunction"> {{row.id}}</td>
<td span @mouseover="showButtonFunction" @mouseleave="hideButtonFunction"> {{row.text}}<button v-if="showBatton">Test</button></td>
<td span @mouseover="showButtonFunction" @mouseleave="hideButtonFunction"> {{row.date_current}}</td>
<td span @mouseover="showButtonFunction" @mouseleave="hideButtonFunction"><button v-if="showBatton">Test</button></td>
</tr>
</tbody>
</table>
正如预期的那样,按钮应该出现在鼠标悬停的行上。但现在它出现在所有可见的线上。
脚本:
data:{
showBatton:false,
},
showButtonFunction(){
// this.title="dsds2"
console.log("test")
this.showBatton=true;
},
hideButtonFunction(){
this.showBatton=false;
}
如何实施?
解决方案
您只能使用 css 执行此操作:
// CSS
tr button {
display: none;
}
tr:hover button {
display: inline-block;
}
// HTML
<tr v-for="row in tasks">
<td span>{{row.id}}</td>
<td span>{{row.text}}<button>Test</button></td>
<td span>{{row.date_current}}</td>
<td span><button>Test</button></td>
</tr>
推荐阅读
- android - 我们自己制作的应用程序在 android 9 中运行良好,但在 android 6 或更早版本中无法运行
- java - 参数和参数有什么区别?
- vega-lite - 用条形图模拟小提琴图
- javascript - 检测浏览器或标签关闭 - Angular
- python - 创建自增函数
- testing - TestNG 链接坏了?对于 Eclipse 响应代码 410
- javascript - 悬停嵌套的 vue 组件
- ruby - 增量历史记录停止 Ruby 2.7.0 IRB 中的历史记录搜索
- node.js - 在 Next.js/NOW 上本地访问 SSR 和 API 路由的机密
- r - 从字符向量中提取字符串时遇到问题