Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JackJones's avatar

How to import Vue?

Hi All,

I'm currently using Vue and going along with Jeff's tutorial

I'm using a CDN and have the code in the Blade template, I'm only on episode 3 or so

I've run

npm i vue

What would I need to type into my app.js file to import Vue so that I'm no longer using a CDN and can practice when I'm offline?

0 likes
3 replies
gych's avatar

Can you share the contents you currently have in your app js file?

In your app.js file you should do something like this:

import { createApp } from "vue";

const app = createApp({});
app.mount('#app');
gych's avatar

@JackJones Remove the script from the blade file and add it in your app.js file

Add this to the head in your app.blade file

@vite(['resources/js/app.js'])

In vite.config.js add app.js as input, like this:

export default defineConfig({
    plugins: [
        laravel({
            input: 'resources/js/app.js',
            refresh: true,
        }),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
    ],
});

In app.js file use this

import { createApp } from "vue";

        let app = {
            components: {
                'app-button': {
                    template: `
                        <button 
                            class="bg-gray-200 hover:bg-gray-400 border rounded px-5 py-2 disabled:cursor-not-allowed" 
                            :disabled="processing"
                        >
                            <slot />
                        </button>
                    `,

                    data() {
                        return {
                            processing: false
                        };
                    }
                },
            }
        };

        createApp(app).mount('#app');

Please or to participate in this conversation.