0

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?

2
  • console.log(this.$auth.getAuthenticatedUser()); does it return what is intended? Commented May 25, 2017 at 11:57
  • Yes, it returns the user Commented May 25, 2017 at 15:31

1 Answer 1

2

In computed you need to return the value you want the property to take.

It should be:

computed: {
  authenticatedUser() {
     return this.$auth.getAuthenticatedUser()
  }
},
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.