3

'laravel8 + vue3 error Uncaught TypeError: Cannot read properties of undefined (reading 'component')

how can this error be avoided ?

app.js

window.Vue = require('vue').default;
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>

hello.vue

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

package.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"
}

this error appears in vue3

tell me how to avoid it

2 Answers 2

8

in Vue3 Your app.js should be like that:

require('./bootstrap');

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

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

app.mount("#app")
Sign up to request clarification or add additional context in comments.

Comments

0

You are using Vue2 setup. Change it to vue3 as above mentioned.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.