[Vuejs]-How to access data ($count) from laravel controller to vue component

4👍

Send count as a prop from blade to component

<your-component-name :count="{{ $count }}"></your-component-name>

And from your component, receive that prop

<template>
    <div>
        Count is {{ count }}
    </div>
</template>

<script>
export default {
    props: {
        count: {
            type: Number
        }
    }
}
</script>

0👍

To pass down data to your components you can use props. Find more info
about props over here. This is also a good source for defining those
props.

You can do something like:

<example :userId="{{ Auth::user()->id }}"></example>

OR

<example v-bind:userId="{{ Auth::user()->id }}"></example>

And then in your Example.vue file you have to define your prop. Then
you can access it by this.userId.

Like :

<script>
  export default {
    props: ['userId'],
    mounted () {
      // Do something useful with the data in the template
      console.dir(this.userId)
    }
  }
</script>

the above question was answered in below question
Pass data from blade to vue component

Leave a comment