0

我尝试安装 laravel 并将 vuejs 与它集成。vuejs 组件未在 laravel 项目中加载。

我的刀片代码是:

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

    <title>{{ config('app.name', 'Laravel') }}</title>

    <script src="{{ asset('js/app.js') }}" defer></script>

    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
    <div id="app">
        <example-component></example-component>
    </div>
</body>
</html>

我的 app.js

require('./bootstrap');

window.Vue = require('vue').default;

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

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

1 回答 1

0

你的 app.js 看起来像使用 Vue2。

你在 Laravel 上安装了 Vue2 吗?

尝试安装 Laravel Breeze。它将为您安装 Vue。我猜安装的版本是 Vue3,而不是 Vue2。

https://laravel.com/docs/9.x/starter-kits#breeze-and-inertia

这是在 Laravel 8 上使用 Vue 3 的一些指南,但它也应该适用于 Laravel 9。我认为你可以关注它的 app.js

https://techvblogs.com/blog/how-to-install-vue3-laravel

于 2022-02-26T17:33:02.347 回答