I'm quite new with Vue. This is confusing the hell out of me.
If I have this while-loop inside of a method.
methods: {
test: function() {
counter = 0;
while( counter < 10 ){
console.log( counter );
counter++;
window.setTimeout( function() {
console.log( 'Test' );
}, 1000)
}
}
},
mounted() {
this.test();
}
Then in my console, it will print this:
0
1
2
3
4
5
6
7
8
9
(10) Test
Correct me if I'm wrong, but shouldn't it write this:
0
Test
1
Test
2
Test
3
Test
4
Test
5
Test
6
Test
7
Test
8
Test
9
Test
... And do it with a seconds delay in-between?
The reason why I'm asking is that I'm pulling data from an API, - and only want to initialize a function, when the data has been populated.
This post, suggest using arrow-functions for the setTimeout, but I'm not seeing any difference when doing it.
And I've looked a lot at Vue's lifecycle, but that didn't show me the answer either.