Recently, I encountered an issue with my dynamically created table. I added the class truncate
to the spans within the td
elements to shorten the log sentences and implemented a title attribute to display the full sentence on hover. However, I noticed that the titles are now appearing for all spans, whereas I only want them to appear for spans with the truncate
class. How can I resolve this?
Vue.component('TheTable', {
template: `<table class="table">
<tr
v-for="(row, i) in data"
>
<td
v-for="(item, index) in row"
>
<span
:title="item"
class="truncate"
>
{{ item }}
</span>
</td>
</tr>
</table>`,
data() {
return {
data: [
[
'very very very very very very very very very very very very very very big sentence',
'very very very very very very very very very very very very very very big sentence',
'very very very very very very very very very very very very very very big sentence'],
['aaa', 'bbb', 'ccc'],
['ddd', 'eee', 'fff']
]
}
}
})
new Vue({
el: "#app",
});
.truncate {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table td {
max-width: 100px;
}
<link type="text/css" rel="stylesheet" href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2909d9d868186809382b2c6dcc7dcc1">[email protected]</a>/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95f7fafae1e6e1e7f4e5b8e3e0f0d5a7bba7a4bba7">[email protected]</a>/dist/bootstrap-vue.css" />
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="681e1d0d285a465e46595a">[email protected]</a>/dist/vue.min.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b7974746f686f697a6b366d6e7e5b2935292a3529">[email protected]</a>/dist/bootstrap-vue.min.js"></script>
<div id="app">
<the-table/>
</div>