Laravel找不到Vue实例

时间:2020-03-27 17:22:28

标签: laravel vue.js components

已安装Laravel,Vue也已安装:

composer require laravel/ui

php artisan ui vue

npm install && npm run dev`

但是,Laravel无法找到在app.js中创建的Vue实例。

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>

        <script src="js/app.js"></script>

    </head>

    <div id="app">
    <example-component></example-component>
    </div>

    <script>
    </script>
  </body>
</html>

浏览器控制台中出现的错误,表明Laravel无法对名为#app的Vue实例进行罚款:

[Vue warn]: Cannot find element: #app

任何帮助将不胜感激:

app.js

require('./bootstrap');

window.Vue = require('vue');

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

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

package.json:

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.19",
        "bootstrap": "^4.0.0",
        "cross-env": "^7.0",
        "jquery": "^3.2",
        "laravel-mix": "^5.0.1",
        "lodash": "^4.17.13",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.20.1",
        "sass-loader": "^8.0.0",
        "vue": "^2.5.17",
        "vue-template-compiler": "^2.6.10"
    }
}

1 个答案:

答案 0 :(得分:-1)

我能够使Vue在Laravel上工作的唯一方法是将其用作正确的示例: https://github.com/connor11528/laravel-vue-spa-tailwindcss