我已经尝试了我能想到的一切,但尽管没有构建错误,但我无法在我非常简单的项目中加载 Vue 组件。我不明白为什么,但在尝试使用 Laravelserve 查看页面时,我只是得到一个空白页面。
welcome.blade.php<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="stylesheet">
</head>
<body class="antialiased">
<div id='app'>
<Home />
</div>
<script scr="{{ asset('js/app.js') }}"></script>
</body>
</html>
app.jsrequire('./bootstrap');
import { createApp } from 'vue'
import Home from './components/Home.vue';
const app = createApp({});
app.component('home', Home);
app.mount('#app');
Home.vue<template>
<div>
<h1> WELCOME </h1>
</div>
</template>
webpack.mix.jsconst mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.vue()
.postCss('resources/css/app.css', 'public/css', [
//
]); Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您是否尝试过将刀片中的标签从
<Home />更改为<home />? 正如另一个用户所写,您必须在导入组件的行中添加 .default由于我的分数,我无法发表评论,抱歉必须像遮阳篷一样做。
您确定
app.component('home', Home);行是导入 comp 的正确方法吗? 因为根据我的发现,这将是Vue.component('home', require('./components/Home.vue').default);就是这样。