D
D
danilr2019-10-30 09:20:16
Vue.js
danilr, 2019-10-30 09:20:16

How to organize project architecture for Vue + Laravel?

There is a laravel project (blade.php) And I need to create Vue components in the same place.
1) Is it possible to make and include single-file .vue components without a faucet? How to do it?
2) If not, how to make common components (reusable) - in what type of file to create, how to connect to blade.php
3) How to make a variant with a assembler - there are a lot of pages, I don’t understand how to set it up at all.
Ps Please describe in more detail, I will be grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolino, 2019-11-01
@Nikolino

In the resources/js/app.js file, you can register components manually (after window.Vue = require('vue')):

/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

Vue.component('something', require('./components/Something.vue').default);
Vue.component('whatever', require('./components/Whatever.vue').default);

And you can also the assembler:
const files = require.context('./', true, /\.vue$/i)
files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

Use them in blade templates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question