【问题标题】:Uncaught ReferenceError: Vue is not defined in Laravel未捕获的 ReferenceError:Laravel 中未定义 Vue
【发布时间】:2023-01-12 17:06:17
【问题描述】:

在使用 vue 3 的 laravel 应用程序中。当我尝试加载 welcome.blade.php 文件时,它不可见 vue 文件内容并且控制台出现以下错误 Uncaught ReferenceError: Vue is not defined <anonymous> http://localhost:8000/js/app.js:37486 app.js 代码行 37486 为 var _Vue = Vue, 我的应用程序.js

require('./bootstrap');
const { createApp } = Vue;
Vue.component('mainapp', require('./components/mainapp.vue').dafault)

const app = createApp({
  /* root component options */
});

app.mount('#app');

和 welcome.blade.php

<html>
<body>
    <div id="app">
            <mainapp></mainapp>
        </div>
    </body>
    <script src="{{mix('/js/app.js')}}"></script>
</html>

我该如何解决这个问题?

我需要一些答案来解决这个问题

【问题讨论】:

    标签: php laravel vue.js


    【解决方案1】:

    我认为你的 app.js 文件中需要这样的东西:

    /**
     * First we will load all of this project's JavaScript dependencies which
     * includes Vue and other libraries. It is a great starting point when
     * building robust, powerful web applications using Vue and Laravel.
     */
    
    require('./bootstrap');
    
    window.Vue = require('vue').default;
    Vue.component('mainapp', require('./components/mainapp.vue').dafault)
    
    /**
     * Next, we will create a fresh Vue application instance and attach it to
     * the page. Then, you may begin adding components to this application
     * or customize the JavaScript scaffolding to fit your unique needs.
     */
    
    const app = new Vue({
        el: '#app'
    });
    
    

    【讨论】:

      猜你喜欢
      • 2021-03-26
      • 2018-05-17
      • 2023-01-23
      • 2020-02-02
      • 2018-04-13
      • 2020-06-21
      • 1970-01-01
      • 1970-01-01
      • 2020-06-14
      相关资源
      最近更新 更多