SQLiteNoob
SQLiteNoob

Reputation: 3022

How to get route parameter from blade to vue

I have a route:

Route::get('/{my_parameter}/home', function($my_parameter) {
    return view('home_view')->with('my_parameter', $my_parameter);
}

In my home_view.blade.php file:

<div>
    {{$my_parameter}} {{-- displays properly --}}
    <vue-component @click="doSomething( {{$my_parameter}} )">Click me</vue-component> {{-- does not work--}}
</div>

I've tried numerous variants as suggested in my searches, including @{{$my_parameter}}. When I use a hard-coded string, @click=doSomething('my_value'), the function works properly.

How do I successfully get a route parameter from blade for use in a vue component? Thank you.

Upvotes: 0

Views: 267

Answers (1)

Joel Hinz
Joel Hinz

Reputation: 25374

I think you just forgot to add quotes around the parameter. If you have doSomething({{ $my_parameter }}) and the parameter is broccoli, it's going to turn into doSomething(broccoli) rather than doSomething('broccoli').

Upvotes: 3

Related Questions