[Vuejs]-How can i get data from php to add json data of vue?

0👍

In order to forward data from PHP to Vue you have multiple options. If your Vue JS code is generated inside a Blade view you can directly render the data into the Vue component.

Another option is to define a shared data layer in global scope. For example: window.myData = {{ json_encode($phpVarWithData) }}. You would do this inside your view file.

Even another option (especially for small data) is to use HTML data attributes inside your view like you already do. You should read the data attributes inside Vue’s livecycle hooks: https://v2.vuejs.org/v2/guide/instance.html#Instance-Lifecycle-Hooks

Actually, v-if="{{ $value->slug }}" looks a bit strange to me. What do you want to archive with this code? The expression evaluates to true if $value->slug is not empty. But my guess is that this value never is empty so the v-if is redundant.

Leave a comment