R
R
ravick2020-06-04 19:30:39
Vue.js
ravick, 2020-06-04 19:30:39

How to add Vue.js component to laravel blade template without app.js?

There is a vue.js component that I use only on one page of the application. I want to cut it out of app.js and add it separately only on this page. I was able to add, but an error arrives from app.js:

[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

That is, you need to somehow tell app.js about this component.

blade pattern:
<div id="app1">
    <demo></demo>
</div>

Component code:
export { Demo }

let Demo = {
    name: 'demo',
    data: function () {
        return {
            message: 'This is a local components.'
        };
    },
    template: '<h1>Component: {{ message }}</h1>'
}

JS:
import { Demo } from './demo.js';

export default {
    components: {
        'demo': Demo
    },
}

let demo = new Vue({
    el: '#app1',
    components: {
        'demo': Demo
    }
})

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question