Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TimiAde's avatar

Php variable in Vue component

Is there any way i can use a php variable in a vue component. Check if it exists and assign it to a prop.

const cat_thread = {{ (isset($op) && $op) ? json_encode($op) : 'null'; }};
export default {
  data() {
    return {
      message:"",
      cat_thread:cat_thread,
      // dataEntries: null,
      categories: []
    }
  },

0 likes
4 replies
tykus's avatar
tykus
Best Answer
Level 104

No, unless this Vue component is being defined in a script tag within a Blade view template?

tykus's avatar

@TimiAde okay, and the script type is a module? Are you seeing an error?

EDIT if it is not in a Blade template, why are you using Blade braces {{ }}?

martinbean's avatar

Is there any way i can use a php variable in a vue component.

@timiade No. PHP has been and gone by the time a single line of JavaScript is executed in your browser.

Instead, pass any data your component needs as props.

Please or to participate in this conversation.