Pass value to component with Vuejs

Asked

Viewed 627 times

2

I have the following structure in my project

 1. App.vue (Arquivo principal)
 2. App.vue (outro arquivo que fica dentro da pasta paginas)
 3. Dashboard.vue (filho do 2 app.vue)

Within my second app.See I call you component Menu, the question is, how would I pass the data to the component Menu?

NOTE: It is a Dashboard, and when logging in, I have the user data, I want to put in the Menu

index.js

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'Login',
      component: Login
    },
    {
      path: '/dashboard',
      name: 'Dashboard',
      children: [
        {
          name: 'DashboardA',
          path: '/',
          component: Dashboard,
          meta: { requiresAuth: true }
        },
        {
          path: '/cardapio',
          name: 'Cardapio',
          component: Itens
        },
        {
          path: '/categorias',
          name: 'Categorias',
          component: Categorias
        },
        {
          path: '/categorias',
          name: 'Categorias',
          component: Categorias
        },
        {
          path: '/subcategorias',
          name: 'SubCategorias',
          component: SubCategorias
        },
        {
          path: '/clientes',
          name: 'Clientes',
          component: Clientes
        }
      ],
      component: AppDashboard
    }
  ]
})

I know that if I call the component on the page, I can pass data via props, but in that case, I’m going to the Dashboard, but the menu is on App.vue, as you would do?

  • Do you have any part of the application managing global state? Vuex? Otherwise you will have to create a mechanism for this. I cannot answer in detail now, but see https://vuejs.org/v2/guide/state-management.html

  • No, I don’t use vuex

  • A good alternative in this case may be using Event bus: https://alligator.io/vuejs/global-event-bus/

1 answer

1

  • I already did, but anyway, Vuex is for state control, it is not recommended to use for login information control.

  • Where did you get that "not recommended for login information"? If you refer to sensitive data (such as password), this should obviously not be stored in the frontend, but if it is non-sensitive data (such as user name, last access date etc), it is natural that it is saved in vuex.

  • When working with login, it is not only user name and last access, we speak of id, is a terrible practice to use the Vuex for this, not least because, the own personal Vuex says it’s for use Vuex only if the project really needs, I do not see the need to use the same for login, control of states, this is the question, if it is to use for one or two things, unnecessario.

Browser other questions tagged

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