«laravel8 vue3 Не может считывать свойства неопределенного (чтение «компонента»)»

#laravel #vue.js #vuejs2 #vue-component #laravel-8

Вопрос:

‘ошибка laravel8 vue3
Uncaught TypeError: Cannot read properties of undefined (reading 'component')

как можно избежать этой ошибки ?

app.js

 window.Vue = require('vue').defau<
Vue.component('hello', require('./hello.vue').default);
const app = new Vue({
    el: '#app'
});
 

welcome.blade.php

 <body class="antialiased">
    <div class="relative flex items-top justify-center min-h-screen bg-gray-100 dark:bg-gray-900 sm:items-center py-4 sm:pt-0">
        <div id="app">
            <hello></hello>
        </div>
    </div>
    <script src="{{mix('js/app.js')}}"></script>
</body>
 

привет,вью

 <template>
    <div>
        Hello World!
    </div>
</template>
 

пакет.json

 "devDependencies": {
    "@vue/compiler-sfc": "^3.2.11",
    "axios": "^0.21",
    "laravel-mix": "^6.0.6",
    "lodash": "^4.17.19",
    "postcss": "^8.1.14",
    "vue": "^3.2.11",
    "vue-loader": "^16.5.0"
}
 

эта ошибка появляется в vue3

скажи мне, как этого избежать

Ответ №1:

в Vue3 твоем app.js должно быть так:

 require('./bootstrap');

import { createApp } from 'vue';
import hello from './components/hello.vue';

let app=createApp({})
app.component('hello' , hello);

app.mount("#app")