在vue js的main.js中使用async api



在main.js中,从vue项目应用程序,我使用API的返回设置一个套接字io url。

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

我的问题是main.js没有异步函数。所以我不能使用async/await。

我怎么能那样做?或者有更好的方法吗?

//main.js示例

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,
},
});

你好,你应该试试这样的东西:

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

最新更新