0π
In an ideal world, all asynchronous functions would already return promises.
But there may be still old libraries that use await
.
You can create a Promise that wraps the await
function as below:
const delay = (ms) => new Promise(resolve => setTimeout(resolve.bind(null, ms/1000), ms));
delay(3*1000).then((sec) => alert(sec + " seconds passed"));
0π
Simulate a click event like this after your api call resolves:
const someFunction = async () => {
const value = await api.someCallToApi();
const link = document.createElement('a');
link.href = 'https://example.com';
link.target = '_blank';
link.click();
link.remove();
}
- [Vuejs]-Vue application. How to skip authentication to show some component?
- [Vuejs]-Vuex component doesn't render on the page
Source:stackexchange.com