0

I'm trying to require a .vue single file component to my php app but i can't make it work without the inline template method. So since i don't have a node main.js to import Vue and require the components, how can i require my .vue or compiled .js component to the component registration?

Working component registration:

Vue.component('example-component', ({
    template: "<div>The component template</div>"
}));

Not working

Vue.component('example-component', require('./components/js/ExampleComponent.vue'));

Thanks!

1 Answers1

0

Try this:

Vue.component('example-component', require('./components/js/ExampleComponent.vue').default);
Anh Tú
  • 636
  • 7
  • 21
  • Thanks for your reply mate, but i'm getting the same error message: **Uncaught ReferenceError: require is not defined** –  May 04 '18 at 08:19
  • You try to run in browser? Check this: https://stackoverflow.com/questions/19059580/client-on-node-uncaught-referenceerror-require-is-not-defined – Anh Tú May 04 '18 at 08:37
  • Oh you are right what a fail. But i already tried to pass .vue single file components to webpack vue-loader and when i include the compiled .js file i get the error: **Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.** –  May 04 '18 at 09:04