How to consume API in Vue to condition a route

Asked

Viewed 19 times

0

I have the following code, I need the const 'exist' to receive information from an api object, I am trying to use Axios but without success.

const existe = informação da api;
export default [
  {
    path: 'clientes/',
    name: 'cadastrar',
    component: () => {
      if (!existe) {
        return import(/* webpackChunkName: "Inicio" */ '@/view/clientes/Cadastrar.vue');
      } else {
        return import(/* webpackChunkName: "Inicio" */ '@/view/clientes/ClienteInfo.vue');
      }
    },
  },
];

1 answer

0

turns its function into asynchronous, and waits for its return for example:

  {
        path: 'clientes/',
        name: 'cadastrar',
        component: await async () => {
    const existe = informação da api;
          if (!existe) {
            return import(/* webpackChunkName: "Inicio" */ '@/view/clientes/Cadastrar.vue');
          } else {
            return import(/* webpackChunkName: "Inicio" */ '@/view/clientes/ClienteInfo.vue');
          }
        },
      },

Browser other questions tagged

You are not signed in. Login or sign up in order to post.