Using async api into main.js of vue js

Viewed 1284

In main.js, from vue project app, I am setting a socket io url using the return of an API.

const url = getAPIAddress(params); //API promises

My problem is that main.js has no async function. So I can´t use async/await.

How could I do that? Or Is there a better way to do it?

//main.js sample

import VueSocketIOExt from "vue-socket.io-extended";
import io from "socket.io-client";
import getAPIAddress from "getAPIAddress";
    
const url = getAPIAddress(params); //API promises
const socket = io(url, { autoConnect: false });
    
Vue.use(VueSocketIOExt, socket, { store });
    
Vue.config.productionTip = false;
    
Vue.use(VuetifyDialog, {
  context: {
    vuetify,
  },
});
1 Answers

Hello you should try something like :

(async () => {
    const url = await getAPIAddress(params); //API promises
    // the rest of the code
})();

Related