15

This may be a really silly question, but nonetheless, something I can't find an answer to.

So, I am building up a Vue component and would like to access vue-spinner's component(s) inside of my component. How would I do that?

Here are snippets of the code in question:

app.js:

Vue.component('players', require('./components/TeamPlayersComponent.vue'));

import GridLoader from 'vue-spinner/src/GridLoader.vue';

const app = new Vue({
    el: '#app',
    components: {
        GridLoader
    }
});

TeamPlayersComponent.vue:

<grid-loader></grid-loader>

Assume that vue-spinner has been installed (NPM) and that the TeamPlayersComponent.vue is valid and working other than giving this error in the console:

vue.js?3de6:525 [Vue warn]: Unknown custom element: <grid-loader> - did you register the component correctly? For recursive components, make sure to provide the "name" option. (found in component <players> at /home/vagrant/code/rounds-smaa/resources/assets/js/components/TeamPlayersComponent.vue)

I am using Vue with Laravel Elixir and Gulp.

2
  • 1
    Have you tried any of the suggested methods in the documentation. Please share what you have tried so far. Commented Jan 4, 2017 at 9:39
  • Question updated, thank you. Commented Jan 4, 2017 at 9:57

4 Answers 4

14

You can get it by following:

var PulseLoader = require('vue-spinner/src/PulseLoader.vue');

and add it in components:

new Vue({
  components: {
    'PulseLoader': PulseLoader
  }
})
Sign up to request clarification or add additional context in comments.

Comments

5

Solution:

Replace the GridLoader specific code in app.js (Laravel setup) with:

Vue.component('grid-loader', require('vue-spinner/src/GridLoader.vue'));

Worked as expected!

Comments

3

I think that you should register the component locally in TeamPlayersComponent.vue file. Import the component and register in the file.

    import gridLoader from 'vue-spinner/src/GridLoader.vue'

Then register the component locally.

    components: {
                gridLoader
               }

Comments

1

You could also import as follows:

import grid-loader from "vue-spinner/src/GridLoader.vue";

and then in then in the component where you want to import it:

components: { grid-loaderfrom }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.