[Vuejs]-Vue + Laravel: String is getting stripped when passed as a prop in blade file

0👍

As stated in the comment below, I think this might be happening because vue is interpreting your $customerId as an equation.

$customerId = time() . rand(0, 100000) . '-' . $redItem->id;

If the $redItem‘s id was 1, this would generate someting like: 155743641671228-1

However, when you v-bind a prop (you’re using the : shorthand to do so), any input provided to it will first be interpreted by javascript. So what you’re seeing when you inspect your prop is the sum of: 155743641671228 – 1 (155743641671227).

Therefore, if you replace the ‘-‘ with something that isn’t a javascript operator when you generate your customer id – it should work.

For example:

$customerId = time() . rand(0, 100000) . ':' . $redItem->id;

I would have thought that removing the v-bind would also cause this to work, but I may be wrong…

Hope it helps!

0👍

This is a string, there is no need to json encode it. nor is there a reason to bind it as its not a variable from the vue instance.


<Flashbar user-ref="{{ $customerId }}" />

Leave a comment