[Vuejs]-How do I access the data in this dynamic import?

0👍

You could resolve it using the then method of the Promise.

import(process.env.VUE_APP_CONFIG).then(myobj => {
  console.log(myobj);
}); 

Or use the async / await syntax to store the value from the Promise in a variable and use it in the same function scope.

(async () => {
  const myobj = await import(process.env.VUE_APP_CONFIG);
  console.log(myojb);
});

Both options are equally effective. The rest all comes down to preference.

Leave a comment