jeudi 25 mai 2017

Show authenticated user in vuejs

I've tried to follow the following tutorial in laravel 5.3 and vue 2.0:

https://www.youtube.com/watch?v=CeXDx4hdT1s

Products.vue:

<my-product :key="product.id"
            v-for="product in products"
            :authenticatedUser="authenticatedUser"
            :product="product">

...

computed: {
  authenticatedUser() {
     this.$auth.getAuthenticatedUser()
  }
},

Product.vue:

export default{
    props: ['product', 'authenticatedUser']
}

Auth.js

setAuthenticatedUser(data){
  authenticatedUser = data;
},

getAuthenticatedUser(){
  return authenticatedUser;
}

Navbar.vue:

export default {
    data() {
        return {
            isAuth: null
        }
    },

    created() {
        this.isAuth = this.$auth.isAuthenticated();

        this.setAuthenticatedUser();
    },

    methods: {
        setAuthenticatedUser() {
            this.$http.get('api/user')
                    .then(response => {
                        this.$auth.setAuthenticatedUser(response.body);
                        console.log(this.$auth.getAuthenticatedUser());
                    })
        }
    }

I try to pass the authenticated user which is called in the Products.vue within the Product.vue

For that, at each login, the setAuthenticated method in the Navbar.vue is called where the authenticated user should be set in the corresponding method.

But when I check the property in the debugger of the browser, it's written Props authenticatedUser: undefinded. In fact the authenticated user is not shown.

Any ideas what it's missing?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qYZTbi
via IFTTT

Aucun commentaire:

Enregistrer un commentaire