3

I have a set of components, some components include other components via @include('my-sub-component')

The issue is that when I want to use vue I have to put the entire component in the vue.js file inside the template tags.

But inside the template I want to use the @include so I can include some sub components. This does not work.

How can I include blade components inside a vue component?

6
  • Share your code. There's no way to figure out why isn't working without code. =) Commented Nov 23, 2017 at 10:57
  • There is no code, I've explained the issue. You should not need code to answer this. Commented Nov 23, 2017 at 10:59
  • stackoverflow.com/questions/38861672/… - does this help at all? I know you say you're using @include but this may be a different way of achieving it Commented Nov 23, 2017 at 11:07
  • Thanks Andy but not quite what i am after. Commented Nov 23, 2017 at 11:12
  • You should have more detailed question, the "component" is Laravel Blade Component or Vue Component. Commented Nov 23, 2017 at 11:48

2 Answers 2

3

As far as I know, it's impossible. You can't use PHP (Laravel Blade) .blade.php tags inside Vue Component .js, of course Vue can't execute PHP script in this case. The possible use case is you use the Vue Component inside Laravel Blade.

Sign up to request clarification or add additional context in comments.

Comments

0

The closest thing you can get to this is to use inline templates. You can't access blade directives it if you are writing your templates in single file components and compiling them with webpack or something because they are not being rendered with PHP.

You could put the style and scripts components in the SFC though and but in order to use blade directives the template would need to be in a .blade.php file

3 Comments

Sure? @include is a blade tag, are you sure Vue can do this? Of course, ithe question is laravel specific use case.
Yes, I've done it before. You might need to escape the VueJS tags because they sorta conflict with the Blade ones. It works because the templates are generated in PHP and not served as a static JS asset.
You should see his explanation How can I include blade components inside a vue component? and he wants to use @include inside Vue Component (.js) file. Your answer is correct, but It's not answering his question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.