I'm trying to apply some inline styles to the element in mounted hook for a short duration as a starting point for a transition.
mounted() {
this.styles = {
backgroundColor: 'silver'
};
After that, on the next tick, I want to add a set of new styles, and let the transition happen
this.$nextTick(() => {
this.styles = {
backgroundColor: 'gold'
}
});
}
This doesn't work as I expect it to, it renders the element with the second style right away.
If I replace the$nextTick
with a setTimeout
, it works as expected.
Where am I wrong? There must be a way to achieve this without relying on a timeout.
I've recreated the problem here
PS I know I could do this with Vue transitions, but in the actual project the styles to be applied are more complex & are programatically calculated, so I'd rather do it in js, than css