Probir
Probir

Reputation: 93

invalid expression: Unexpected identifier in vue js

I am having problems sending compact data from controller to vue component as a props.

Code for Blade file:

<div id="hotjob">
    <hotjob-component :projects="'{{ json_encode($Projects) }}'"></hotjob-component>
</div>

I also tried with {!! json_encode($Projects) !! but it's still not working.

Code for Vue File:

props: ['projects'],
created()
{

    console.log('From On created');
    console.log(this.projects);
},
mounted()
{
    console.log(this.projects);
    console.log('Hot Job Mounted yeah');
}

This is the error I get:

invalid expression: Unexpected identifier in

Upvotes: 2

Views: 7082

Answers (2)

Shanaka Nuwan
Shanaka Nuwan

Reputation: 175

Try with removing single quotes

    <div id="hotjob">
     <hotjob-component :projects="{{ json_encode($Projects) }}"></hotjob-component>
    </div>

Like this.

Upvotes: 2

Jodeveloper8
Jodeveloper8

Reputation: 104

just pass the variable to the props directly :

<hotjob-component :projects='{{ $Projects }}'></hotjob-component>

this should do it

Upvotes: 0

Related Questions