3

I currently have a Laravel route leading to the index function of my controller with a passed ID, where I return the id in a view

public function index($id)
{
    return view('progress')
        ->with('identifier', $id);
}

In the component loaded in said view I'm trying to access the identifier as a prop in my vue script

props: ['identifier'],
    methods: {
        getInformation() {
            this.$root.$emit('fetchEvent');
        },
    },
    mounted () {
        console.dir(this.identifier);
    }

However, my console says undefined and I can't figure out how to get the passed identifier as a prop.

What am I doing wrong?

update:

full template code

<template>
    <div>
        <div class="tab-content">                
                <item-component 
                    :web-identifier="identifier"
                ></item-component>
        </div>
    </div>

</template>


<script>
export default {
   props: ['identifier'],
    methods: {
        getInformation() {
            this.$root.$emit('fetchEvent');
        },
    },
    mounted () {
        console.dir(this.identifier);
    }
}
</script>

blade:

<div>
<task-detail-component></task-detail-component>
</div>
6
  • how do you pass the prop in your progress template Commented Aug 27, 2019 at 17:52
  • The bottom section of code is my progress template. I guess that's what I'm not sure of, I'm trying to make identifier accessible within the template through props Commented Aug 27, 2019 at 17:57
  • please share the progress template code Commented Aug 27, 2019 at 17:58
  • @BoussadjraBrahim there isn't much else but I shared it Commented Aug 27, 2019 at 18:01
  • where and how you're calling that component in blade template Commented Aug 27, 2019 at 18:02

2 Answers 2

2

in blade template pass that data as follows :

<div>
<task-detail-component :identifier="{{$identifier}}"></task-detail-component>
</div>
Sign up to request clarification or add additional context in comments.

5 Comments

Ok, so is there a reason why my console portion shows undefined?
or try <task-detail-component :identifier="{{$identifier}}"></task-detail-component> with $identifier
on building I get a compile error for unexpected token {
It is. Blade view injected variables are not available to the browser unless you explicitly bind them that way.
I see now, that got it I believe. Thanks!
0

in your template where you need to pass your identifier it will be like this

<div>
<task-detail-component :identifier="{{$identifier}}"></task-detail-component>
</div>

4 Comments

ok I see, so why is the console printing undefined where I'm trying to show it in the console?
did you make sure that you pass the identifier variable to view that contains this component?
You can see where I;m passing it to the view in my controller above
try to make it as api and fetch it in your component from ajax with axios

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.