Laravel,Vue组件未加载

时间:2020-05-24 13:48:56

标签: laravel vue.js

最初,vue组件正在运行并正在加载,但是突然之间我开始出现此错误[Vue警告]:未知的自定义元素:-您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。我没有更改任何代码,并且在新文件上也出现了此错误。

<template>
<v-app>
    <div class="example-component">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Example Component</div>

                    <div class="card-body">
                        I'm an example component.
                    </div>
                </div>
            </div>
        </div>
    </div>
</v-app>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

@extends('layouts.app')

@section('content')
<div id="app">
<ExampleComponent />
</div>
@endsection

/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');

/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

Vue.component('example-component', require('./components/ExampleComponent.vue').default);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

const app = new Vue({
    el: '#app',
});

这是我的vue文件,要在其中使用vue组件的home.blade.php文件和我的app.js文件

1 个答案:

答案 0 :(得分:1)

组件的名称为“ example-component”,因此您应该更改

@section('content')
<div id="app">
<ExampleComponent />
</div>
@endsection

@section('content')
<div id="app">
<example-component />
</div>
@endsection