0

I recently started converting my laravel 8 project to VueJS, but it does not seem to render it's template content. Well, i used the following commands to include basic structure of Vue: php artisan ui vue && npm install

app.js:

require('./bootstrap');

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

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

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

webpack.mix.js:

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');

Main view:

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
</head>
<body id="app">
    <example-component></example-component>

    <script type="text/javascript" src="{{ asset('js/app.js') }}"></script>
</body>
</html>

Npm build works well, there're no errors. But unfortunately, the templates content is not visible in the frontend. Everything I see is the vue-tag itself like:

enter image description here

Thanks in advance!

9
  • Does this answer your question? Laravel Vue You may need an appropriate loader to handle this file type, Commented Jan 25, 2021 at 11:15
  • Not really, I'm still using laravel-mix 5.0.5 Commented Jan 25, 2021 at 11:21
  • then try npm i && npm run dev Commented Jan 25, 2021 at 11:25
  • Same, building works fine but still no frontend output. :/ Commented Jan 25, 2021 at 11:29
  • 1
    window.Vue = require('vue').default; to window.Vue = require('vue') try this Commented Jan 25, 2021 at 11:53

1 Answer 1

2

the root component shouldn't be mounted in body element, you've to do something like :

<body >
   <div id="app">
    <example-component></example-component>
  </div>
    <script type="text/javascript" src="{{ asset('js/app.js') }}"></script>
</body>

and remove default from window.Vue = require('vue').default; :

require('./bootstrap');

window.Vue = require('vue');

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

const app = new Vue({
    el: '#app',
});
Sign up to request clarification or add additional context in comments.

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.