You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 10集成Laravel Breeze后Vue组件内容不显示求助

Laravel 10 + Breeze + Vue 组件无法显示(无控制台报错)

我正在使用Laravel 10,已搭建好Laravel Breeze与Vue环境,但Vue组件内容无法显示,浏览器控制台无任何报错信息。以下是我的配置文件及页面渲染情况:

Composer.json

{
  "require": {
    "php": "^8.1",
    "guzzlehttp/guzzle": "^7.2",
    "laravel/breeze": "^1.23",
    "laravel/framework": "^10.10",
    "laravel/sanctum": "^3.2",
    "laravel/tinker": "^2.8"
  },
  "require-dev": {
    "fakerphp/faker": "^1.9.1",
    "laravel/pint": "^1.0",
    "laravel/sail": "^1.18",
    "mockery/mockery": "^1.4.4",
    "nunomaduro/collision": "^7.0",
    "phpunit/phpunit": "^10.1",
    "spatie/laravel-ignition": "^2.0"
  }
}

package.json

{
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  },
  "devDependencies": {
    "@tailwindcss/forms": "^0.5.2",
    "@vitejs/plugin-vue": "^4.3.4",
    "alpinejs": "^3.4.2",
    "autoprefixer": "^10.4.2",
    "axios": "^1.1.2",
    "laravel-vite-plugin": "^0.8.0",
    "postcss": "^8.4.6",
    "tailwindcss": "^3.1.0",
    "vite": "^4.0.0"
  },
  "dependencies": {
    "npm-watch": "^0.11.0",
    "vue": "^3.2.36",
    "vue-loader": "^17.2.2",
    "vue-router": "^4.0.13"
  }
}

vite.config.js

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
            ],
            refresh: true,
        }),

        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
});

app.js

import './bootstrap';

import { createApp } from "vue";
import ExampleComponent from './components/Examplecomponent.vue'

createApp({
    components: {
        ExampleComponent,
    }
}).mount('#app')

ExampleComponent.vue

<template>
  <div>
    this is example vue 3
  </div>
</template>

welcome.blade.php

<body class="antialiased">
   <h1>Hello</h1>
   <div id="app">
       hi...
       <example-component></example-component>
   </div>
</body>

浏览器构建后的页面检查结果

<html lang="en"><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Laravel</title>

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.bunny.net">
    <link href="https://fonts.bunny.net/css?family=figtree:400,600&display=swap" rel="stylesheet">

    <!-- Styles -->
    <link rel="preload" as="style" href="http://127.0.0.1:8000/build/assets/app-993b5797.css"><link rel="modulepreload" href="http://127.0.0.1:8000/build/assets/app-12031083.js"><link rel="stylesheet" href="http://127.0.0.1:8000/build/assets/app-993b5797.css"><script type="module" src="http://127.0.0.1:8000/build/assets/app-12031083.js"></script>    </head>
<body class="antialiased">
<h1>Hello</h1>
   <div id="app" data-v-app=""><!----></div>

不确定遗漏了什么配置,导致Vue组件内容无法显示且无控制台报错。


排查与解决步骤

  • 修正文件名大小写:你导入的组件文件是Examplecomponent.vue(小写c),但注册的组件名是ExampleComponent(大写C)。类Unix系统区分文件名大小写,会导致组件无法加载。将文件名改为ExampleComponent.vue,或导入语句匹配原文件名的大小写。
  • 确认Vite服务状态:确保执行了npm run dev启动Vite开发服务器,未启动的话资源无法实时编译。
  • 清理缓存:执行php artisan optimize:clear清理Laravel缓存,同时重启Vite服务,避免缓存导致的资源加载异常。
  • 调整组件注册方式:如果以上步骤无效,尝试全局注册组件:
    import './bootstrap';
    import { createApp } from "vue";
    import ExampleComponent from './components/ExampleComponent.vue'
    
    const app = createApp({});
    app.component('example-component', ExampleComponent);
    app.mount('#app');
    

内容的提问来源于stack exchange,提问作者Pradeep Rajvanshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 12:37:02