samedi 24 août 2019

Declaring new vue components in multiple files in Laravel

Up until now all vue components have been declared in app.js, but since this file contains all the javascript for the entire site, it takes a second or two to load.

There is one component (a search bar) that needs to load quickly. Is it possible to have this component load in a seperate js file so it can load faster?

I have tried creating a new js file search.js which contains:

require('./bootstrap');

import Vue from 'vue';

window.Vue = require('vue');

Vue.component('searchbar', require('./components/SearchBar.vue'));

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

However when I try to use <searchbar></searchbar> I get the error Unknown custom element: <searchbar> - did you register the component correctly?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire