简体   繁体   中英

Vue.js in Laravel

I am trying to use vue.js with laravel for the first time.

In the blade.php file:

<html>
    <body class>
        <div id="app"> 
            <favourup></favourup>
        </div>
        <script src="{{ asset('js/app.js') }}"></script>
    </body>
</html>

In the app.js file:

Vue.component('favourup', require('./components/Favourup.vue'));

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

In the vue file:

<template>
    <div>
        <h2>FavourUp</h2>
    </div>
</template>

I am not getting any errors however the local host displays an empty web page when it should display 'FavourUp'

you should write.default at end of require vue components because of part of the vue-loader 15 updates, if your code uses the CommonJS syntax for importing EcmaScript modules, you'll need to append.default: https://laravel-mix.com/docs/4.0/upgrade#importing-es-modules but as @Ifaruki said you can import it too here's the code:

// first
Vue.component('favourup', require('./components/Favourup.vue').default);

// second
import Favourup from './components/Favourup.vue';

Vue.component('favourup', Favourup);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM