T
T
tyraelqp2018-12-09 22:23:33
webpack
tyraelqp, 2018-12-09 22:23:33

How to compile .vue components into separate .js files?

There is, for example, the following file structure:

resources
    js
        components
            ContactForm.vue
            OrderForm.vue

How to compile them into separate files through laravel mix in order to include them only on the necessary pages?
Like this:
<script src="{{ mix('js/vendors.js` }} " ></script> тут VUE
<script src="{{ mix('js/components/ContactForm.js` }} " ></script> компоненты 
<script src="{{ mix('js/app.js` }} " ></script> инициализация

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2018-12-09
@kicker1337

You can separate the components into folders like so:

resources
    js
        components
            ContactForm
                index.js
                component.vue
            OrderForm.vue
                index.js
                component.vue

Then inside each index.js:
import component from './component.vue'

// регистрирует глобальный компонент
Vue.component('имя компонента', component);

Connect like this:
maybe it will work like this:
I think it will work.
And let this be at the end of all scripts:
<script src="{{ mix('js/app.js` }}"></script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question