3

As the title says it all, I will still guide you to reproduce the issue. Details are below.

Steps to reproduce

  1. Clone Laravel official project from Github
  2. Install all dependencies of Php and JavaScript (Node)
    • npm install - for node
    • composer install - for php

After installing all dependencies

  1. Open up resources/views/welcome.blade.php and edit it to the following code below

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Mix</title>
    
    <link rel="stylesheet" href="{{ mix('css/app.css') }}">
    </head>
    
    <body>
    
    <div id="app">
      <h1>Hello, world!</h1>
    
      <example-component />
      <camel-case-component />
    </div>
    
    <script src="{{ mix('js/app.js') }}"></script>
    
    </body>
    
    </html>
    
  2. Open up resources/js/app.js and edit it to the following code below

    require('./bootstrap');
    
    window.Vue = require('vue');
    
    Vue.component('camel-case-component', require('./components/CamelCaseComponent.vue').default);
    Vue.component('example-component', require('./components/ExampleComponent.vue').default);
    
    const app = new Vue({
        el: '#app'
    });
    

    Note: Do not forget to add the file resources/js/components/CamelCaseComponent.vue

  3. Run the laravel mix, npm run dev

  4. Serve your app, php artisan serve and open it using any browser http://127.0.0.1:8000/

That's it. Minimal modification only.

4
  • 1
    What does "not working properly" mean? Are you seeing errors in either your logs or the browser console? Also, what is CamelCaseComponent.vue? — it's not part of the Laravel package that I have ever seen, and I don't see it in the official repo link you posted. Commented Aug 28, 2019 at 2:40
  • Have you tried to reproduce the issue? To answer you, I don't see any errors from console and from vue tools it only shows one component (which is the example-component since it is the first component typed) CamelCaseComponent.vue is something you will create. See the **Note: ** under number 2. Commented Aug 28, 2019 at 3:27
  • 1
    Yes, I saw the note, but "add" is an ambiguous term — add from where? It's seems you really meant "create." I am unable to reproduce your issue. From what you have said, Laravel is loading the page and Vue is loading the example component. This means the only thing not loading is your custom component, right? Can you post the contents of your CamelCaseComponent.vue file? Commented Aug 28, 2019 at 4:07
  • Oh, my mistakes. CamelCaseComponent.vue can contain anything, let's say a dummy text. On a side note, try to re-arrange them. Insert the CamelCaseComponent first then followed by ExampleComponent. You will see, CamelCaseComponent will load but ExampleComponent will be missing. Commented Aug 28, 2019 at 5:19

2 Answers 2

10
+50

Try this

<example-component></example-component>
<camel-case-component></camel-case-component>

Instead of

<example-component /> 
<camel-case-component />

I used closing tags for each component instead of self-closing tag.

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

2 Comments

Not sure why, but this works! Both components are shown when using the closing-tag instead of a self-closing tag.
6

HTML

So the problem is that HTML does not allow custom elements to be self-closing. Only "official void" elements can use self-closing; <link href="style.css" /> for example.

Because blade templates need to be valid HTML you should change it to

<example-component></example-component>
<camel-case-component></camel-case-component>

Vue Templates

Vue templates are parsed, so they don't need to adhere to the official HTML syntax. Vue actually recommends to use self-closing tags in other Vue components.

So having

<example-component />
<camel-case-component />

In a Vue template would be totally fine.

For more details about this you can check out the official Vue documentation

Comments

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.