Vue 3-Komponenten können im Laravel-Projekt nicht angezeigt werden
P粉032900484
P粉032900484 2024-02-26 11:54:25
0
2
351

Ich habe alles versucht, was mir einfällt, aber obwohl ich keine Build-Fehler bekomme, schaffe ich es nicht, die Vue-Komponenten in mein sehr einfaches Projekt zu laden. Ich verstehe nicht warum, aber wenn ich versuche, die Seite mit Laravelserve anzuzeigen, erhalte ich nur eine leere Seite.

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.js

require('./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.js

const 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', [
        //
    ]);

P粉032900484
P粉032900484

Antworte allen(2)
P粉262073176

您是否尝试过将刀片中的标签从 <Home /> 更改为 <home /> ? 正如另一个用户所写,您必须在导入组件的行中添加 .default

P粉946336138

由于我的分数,我无法发表评论,抱歉必须像遮阳篷一样做。


您确定 app.component('home', Home); 行是导入 comp 的正确方法吗? 因为根据我的发现,这将是

Vue.component('home', require('./components/Home.vue').default);

就是这样。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!