I'm utilizing a vue.js component with the <transition>
element for show/hide animations. However, I want to disable the animation for faster testing. How can I achieve this?
The solution proposed is
* { transition: none !important }
in this link: https://github.com/vuejs/vue/issues/463, but it doesn't seem to work.
You can check out my fiddle here: https://jsfiddle.net/z11fe07p/2268/
When running the "test," the final output shows "3. Display should be 'none', it is: block." Increasing the timeout or removing the <transition>
element gives the expected result of "3. Display should be 'none,' it is: none."
Could someone guide me on how to disable the animation and eliminate the need for setTimeout
calls?
UPDATE:
I've tried removing all CSS styling without any success. Hence, the issue seems to stem from having the <transition>
element alone.
UPDATE 2:
I've revised the fiddle to contain only the <transition>
element along with calls to $nextTick()
to rule out any odd behavior causes.
If you modify the call from wait100
to wait10
, you'll notice that the test begins to fail.
https://jsfiddle.net/z11fe07p/2270/
UPDATE 3:
Sharing the example code below for easier experimentation :)
new Vue({
el: '#app',
template: `
<span>
<button @click="test()">Run test</button>
<transition>
<p v-show="show">Hello, world!</p>
</transition>
</span>
`,
data() {
return {
show: false,
};
},
methods: {
test() {
const wait10 = _ => new Promise(resolve => setTimeout(resolve, 10));
const wait100 = _ => new Promise(resolve => setTimeout(resolve, 100));
const showParagraph = _ => this.show = true;
const hideParagraph = _ => this.show = false;
const p = document.querySelector('p');
showParagraph();
this.$nextTick()
.then(wait10)
.then(() => {
const display = getComputedStyle(p).display;
assertEqual(display, 'block');
})
.then(hideParagraph)
.then(this.$nextTick)
.then(wait100)
.then(() => {
const display = getComputedStyle(p).display;
assertEqual(display, 'none');
});
}
}
});
function assertEqual(a, b) {
if (a !== b) {
console.error('Expected "' + a + '" to equal "' + b + '"');
}
};
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>
<div id="app"></div>