I have a vuetify tooltip component. In the tooltip I have a {{date | moment}}
. I get a static a few seconds ago
.
I want every time I hover over the button, to refresh the button tooltip to the current elapsed time (10 minutes ago
for example).
I can’t figure out how to rerender the tooltip on hover with the updated filter.
JavaScript
x
6
1
filters: {
2
moment: function (date) {
3
return moment(date).fromNow();
4
},
5
},
6
Advertisement
Answer
If I understood correctly about what you are trying to achieve, this idea might help you (below is the code pen link):
simulated elapsed time on button hover
JavaScript
1
20
20
1
<div id="app">
2
<v-app id="inspire">
3
<div class="text-center d-flex align-center justify-space-around">
4
<v-tooltip bottom>
5
<template v-slot:activator="{ on, attrs }">
6
<v-btn
7
color="primary"
8
dark
9
class="mt-10"
10
v-bind="attrs"
11
v-on="on"
12
@mouseover="setElapsedTime"
13
>
14
Button
15
</v-btn>
16
</template>
17
<span>{{ elapsedTime }}</span>
18
</v-tooltip>
19
</div>
20
JavaScript
1
16
16
1
new Vue({
2
el: '#app',
3
vuetify: new Vuetify(),
4
data() {
5
return {
6
startTime: Date.now(),
7
elapsedTime: '',
8
}
9
},
10
methods: {
11
setElapsedTime() {
12
const millis = Date.now() - this.startTime;
13
this.elapsedTime = `seconds elapsed = ${Math.floor(millis / 1000)}`;
14
}
15
} })
16
tooltip text is bound to a variable in the data object, whenever the user hover over the button, a method is called which updates the variable in the data object