javascript - Error compiling template: Component template requires a root element, rather than just text in vue.js with laravel

I am Learner in Vuejs with laravel, i created a fresh project in laravel, with vue.js frontend. but aft

I am Learner in Vuejs with laravel, i created a fresh project in laravel, with vue.js frontend. but after run mand php artisan serve, when i run project on webbrowser. output is blank. i checked network console, there is also the output showing in example ponent is blank. please help me to find my mistake.

web.php


    Route::get('/', function () {
        return view('wele');
    });

wele.blade.php


    <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
    
            <title>Laravel Vue</title>
    
            <!-- Fonts -->
            <link href=":200,600" rel="stylesheet">
        </head>
        <body>
            <div id="app">
                <example-ponent> </example-ponent>
                <script src="{{ asset('js/app.js') }}"></script>
            </div>
        </body>
    </html>

ExampleComponent.vue


    <script>
    
    Vueponent('example-ponent', {
     
      template: `This is the homepage`
    })
    
    new Vue({
         el: '#app'
          })
    </script>

app.js


    import Vue from 'vue'
    import VueRouter from 'vue-router'
    
    Vue.use(VueRouter)
    
    require('./bootstrap');
    
    window.Vue = require('vue');
    
    alert('Alert');
    Vueponent('example-ponent', require('./ponents/ExampleComponent.vue').default);

I am Learner in Vuejs with laravel, i created a fresh project in laravel, with vue.js frontend. but after run mand php artisan serve, when i run project on webbrowser. output is blank. i checked network console, there is also the output showing in example ponent is blank. please help me to find my mistake.

web.php


    Route::get('/', function () {
        return view('wele');
    });

wele.blade.php


    <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
    
            <title>Laravel Vue</title>
    
            <!-- Fonts -->
            <link href="https://fonts.googleapis./css?family=Nunito:200,600" rel="stylesheet">
        </head>
        <body>
            <div id="app">
                <example-ponent> </example-ponent>
                <script src="{{ asset('js/app.js') }}"></script>
            </div>
        </body>
    </html>

ExampleComponent.vue


    <script>
    
    Vue.ponent('example-ponent', {
     
      template: `This is the homepage`
    })
    
    new Vue({
         el: '#app'
          })
    </script>

app.js


    import Vue from 'vue'
    import VueRouter from 'vue-router'
    
    Vue.use(VueRouter)
    
    require('./bootstrap');
    
    window.Vue = require('vue');
    
    alert('Alert');
    Vue.ponent('example-ponent', require('./ponents/ExampleComponent.vue').default);

Share Improve this question asked Aug 31, 2020 at 12:31 Parteek Kumar KherpaParteek Kumar Kherpa 1953 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5
Vue.ponent('example-ponent', {
  template: `<div id="app">This is the homepage</div>`
})

You have to wrap the template content in a parent element, such as <div> </div>. If not Vue will show an error, explaining that every ponent must have a single root element.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745271554a4619777.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信